56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
public sealed partial class Dedugan
|
|
{
|
|
private void UpdateMovement()
|
|
{
|
|
_directionToAxis = OverrideGravity == Vector3.Zero
|
|
? Vector3.VectorPlaneProject(WorldPosition, Vector3.Right).Normal
|
|
: OverrideGravity;
|
|
|
|
_up = -_directionToAxis;
|
|
_forward = Vector3.Right;
|
|
_right = Vector3.Cross(_up, _forward).Normal;
|
|
|
|
Controller.Up = _up;
|
|
Controller.VectorGravity = -_up * 850f;
|
|
|
|
if (Network.IsOwner)
|
|
{
|
|
LookAtSurfaceNormal(_up, _forward);
|
|
_wishDirection = Input.AnalogMove.Normal * Rotation.FromYaw(EyeAngles.yaw) * WorldRotation;
|
|
|
|
var isDucking = Input.Down("Duck");
|
|
var isRunning = Input.Down("Run");
|
|
var wishSpeed = isDucking ? DuckSpeed : isRunning ? RunSpeed : WalkSpeed;
|
|
|
|
var ragdollMul = RagdollController.Enabled ? 0f : 1f;
|
|
Controller.WishVelocity = _wishDirection * wishSpeed * ragdollMul;
|
|
|
|
if (Input.Pressed("Jump") && Controller.IsOnGround)
|
|
{
|
|
Controller.Punch(-Controller.AppliedGravity.Normal * JumpStrength);
|
|
AnimationHelper?.TriggerJump();
|
|
}
|
|
|
|
IsDucking = Input.Down("Duck") ? 1f : 0f;
|
|
}
|
|
|
|
if (!RagdollController.Enabled)
|
|
Controller.Move();
|
|
else
|
|
Controller.Velocity = 0;
|
|
|
|
if (!AnimationHelper.IsValid()) return;
|
|
|
|
AnimationHelper.DuckLevel = IsDucking;
|
|
AnimationHelper.WithWishVelocity(Controller.WishVelocity);
|
|
AnimationHelper.WithVelocity(Controller.Velocity);
|
|
AnimationHelper.IsGrounded = Controller.IsOnGround;
|
|
}
|
|
|
|
private void LookAtSurfaceNormal(Vector3 up, Vector3 moveDirection)
|
|
{
|
|
var newRotation = Rotation.LookAt(moveDirection, up);
|
|
WorldRotation = Rotation.Lerp(WorldRotation, newRotation, Time.Delta * 10f);
|
|
}
|
|
}
|