Initial commit

This commit is contained in:
2023-07-09 21:04:23 -07:00
parent 970d47c2ae
commit f32534b55b
22 changed files with 409 additions and 0 deletions

51
Scripts/Player.cs Normal file
View File

@@ -0,0 +1,51 @@
using Godot;
public partial class Player : CharacterBody3D
{
[Export]
private int _speed { get; set; } = 14;
[Signal]
public delegate Vector3 MoveEventHandler();
public override void _PhysicsProcess(double delta)
{
Velocity = ProcessMovement();
MoveAndSlide();
EmitSignal(SignalName.Move, Position);
}
private Vector3 ProcessMovement()
{
var direction = Vector3.Zero;
var targetVelocity = Vector3.Zero;
if (Input.IsActionPressed("move_right"))
{
direction.X += 1.0f;
}
if (Input.IsActionPressed("move_left"))
{
direction.X -= 1.0f;
}
if (Input.IsActionPressed("move_back"))
{
direction.Z += 1.0f;
}
if (Input.IsActionPressed("move_forward"))
{
direction.Z -= 1.0f;
}
if (direction != Vector3.Zero)
{
direction = direction.Normalized();
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
}
// Ground velocity
targetVelocity.X = direction.X * _speed;
targetVelocity.Z = direction.Z * _speed;
return targetVelocity;
}
}