using Godot; using Movementtests.interfaces; namespace Movementtests.scenes.movement; public partial class CGroundedMovement : Node3D, IMoveable { [Export] public RMovement RMovement { get; set; } [Export] public RayCast3D WallInFrontRayCast { get; set; } public Vector3 ComputeVelocity(MovementInputs inputs) { var velocity = inputs.Velocity; var target = inputs.TargetLocation; var direction = (target - GlobalPosition).Normalized(); var targetPlane = new Vector3(target.X, GlobalPosition.Y, target.Z); LookAt(targetPlane); float xAcc = (float) Mathf.Lerp(velocity.X, direction.X * RMovement.Speed, inputs.delta * RMovement.Acceleration); float zAcc = (float) Mathf.Lerp(velocity.Z, direction.Z * RMovement.Speed, inputs.delta * RMovement.Acceleration); velocity.X = xAcc; velocity.Z = zAcc; if (WallInFrontRayCast.IsColliding()) velocity.Y = RMovement.Speed; else if (!inputs.isOnFloor) velocity += inputs.gravity * (float)inputs.delta * RMovement.GravityModifier; return velocity; } }