33 lines
914 B
C#
33 lines
914 B
C#
using Godot;
|
|
using Movementtests.interfaces;
|
|
|
|
namespace Movementtests.scenes.movement;
|
|
|
|
public partial class CGroundedMovement : Node3D, IMoveable
|
|
{
|
|
[Export] public RMovement RMovement;
|
|
|
|
[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);
|
|
|
|
velocity.X = direction.X * RMovement.Speed;
|
|
velocity.Z = direction.Z * RMovement.Speed;
|
|
|
|
if (WallInFrontRayCast.IsColliding())
|
|
velocity.Y = RMovement.Speed;
|
|
else if (!inputs.isOnFloor)
|
|
velocity += inputs.gravity * (float)inputs.delta;
|
|
|
|
return velocity;
|
|
}
|
|
} |