Files
MovementTests/player_controller/Scripts/CapsuleCollider.cs
2026-01-14 15:26:41 +01:00

53 lines
1.3 KiB
C#

using Godot;
namespace Movementtests.player_controller.Scripts;
public partial class CapsuleCollider : CollisionShape3D
{
[Export(PropertyHint.Range, "0,5.0,0.01,suffix:m,or_greater")]
public float CapsuleDefaultHeight { get; set; } = 2.0f;
[Export(PropertyHint.Range, "0,5.0,0.01,suffix:m,or_greater")]
public float CapsuleCrouchHeight { get; set; } = 1.0f;
public float GetCurrentHeight() { return _shape.Height; }
public float GetDefaultHeight() { return CapsuleDefaultHeight; }
private CapsuleShape3D _shape;
public override void _Ready()
{
_shape = Shape as CapsuleShape3D;
_shape.Height = CapsuleDefaultHeight;
}
public bool IsCapsuleHeightLessThanNormal()
{
return _shape.Height < CapsuleDefaultHeight;
}
public bool IsBetweenCrouchingAndNormalHeight()
{
return _shape.Height > CapsuleCrouchHeight && _shape.Height < CapsuleDefaultHeight;
}
public bool IsDefaultHeight()
{
return Mathf.IsEqualApprox(_shape.Height, CapsuleDefaultHeight);
}
public bool IsCrouchingHeight()
{
return Mathf.IsEqualApprox(_shape.Height, CapsuleCrouchHeight);
}
public void Crouch()
{
_shape.Height = CapsuleCrouchHeight;
}
public void Uncrouch()
{
_shape.Height = CapsuleDefaultHeight;
}
}