48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using Godot;
|
|
|
|
namespace DRPGActionGame.Player.States;
|
|
|
|
public partial class MoveState : State {
|
|
|
|
public override void _Ready() {
|
|
base._Ready();
|
|
Player.Playback?.Travel("move");
|
|
}
|
|
|
|
public override void _Input(InputEvent @event) {
|
|
if (@event.IsAction("Jump")) {
|
|
Player.ChangeState(StateFactory.States.Jump);
|
|
}
|
|
else if (@event.IsAction("Attack")) {
|
|
Player.ChangeState(StateFactory.States.Attack);
|
|
}
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta) {
|
|
Vector3 velocity = Player.Velocity;
|
|
|
|
if (Player.Direction != Vector3.Zero) {
|
|
if (Player.PlayerMesh != null) {
|
|
Vector3 rotation = Player.PlayerMesh.Rotation;
|
|
rotation.Y = (float)Mathf.LerpAngle(Player.PlayerMesh.Rotation.Y, float.Atan2(Player.Direction.Y, Player.Direction.Z) - Player.PlayerMesh.Rotation.Y, delta * 10f);
|
|
Player.PlayerMesh.Rotation = rotation;
|
|
}
|
|
else {
|
|
GD.PrintErr("No PlayerMesh defined!");
|
|
}
|
|
|
|
velocity.X = Player.Direction.X * Player.SPEED;
|
|
velocity.Z = Player.Direction.Z * Player.SPEED;
|
|
}
|
|
else {
|
|
Player.ChangeState(StateFactory.States.Idle);
|
|
}
|
|
|
|
Player.Velocity = velocity;
|
|
}
|
|
|
|
public override void ExitState() {
|
|
// GD.Print("Exit move state...");
|
|
QueueFree();
|
|
}
|
|
} |