You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/Player3D.cs

29 lines
817 B

using Godot;
namespace Babushka.scripts.CSharp.Common;
public partial class Player3D : CharacterBody3D
{
[Export] private float _speed = 1.0f;
[Export] private Camera3D _camera;
public override void _PhysicsProcess(double delta)
{
if (!IsOnFloor()) Velocity += Vector3.Down * (float) delta;
var inputDir = Input.GetVector("move_left", "move_right", "move_up", "move_down");
inputDir = inputDir.Rotated(-_camera.GlobalRotation.Y);
var direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
if (direction != Vector3.Zero)
{
Velocity = new Vector3(direction.X * _speed, Velocity.Y, direction.Z * _speed);
}
else
{
Velocity = Velocity.MoveToward(new Vector3(0, 0, 0), _speed);
}
MoveAndSlide();
}
}