60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using Godot;
|
|
using System;
|
|
using DungeonRPG.Scripts.General;
|
|
|
|
public partial class Player3D : CharacterBody3D
|
|
{
|
|
[Export] public AnimationPlayer AnimationPlayer {get; private set;}
|
|
[Export] public Node3D PlayerBody {get; private set;}
|
|
[Export] public StateMachine StateMachine {get; private set;}
|
|
|
|
[Export] private CharacterMeshSwapper MeshSwapper;
|
|
|
|
public Vector2 Direction;
|
|
private float _currentAngle;
|
|
public override void _Ready()
|
|
{
|
|
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
if(Direction == Vector2.Zero) return;
|
|
|
|
float target = Mathf.Atan2(Direction.X, Direction.Y);
|
|
_currentAngle = PlayerBody.Rotation.Y;
|
|
|
|
float newAngle = (float)Mathf.LerpAngle(_currentAngle, target, delta * 20);
|
|
|
|
PlayerBody.Rotation = new Vector3(0, newAngle, 0);
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
Direction = Input.GetVector(
|
|
GameConstants.INPUT_MOVE_LEFT,
|
|
GameConstants.INPUT_MOVE_RIGHT,
|
|
GameConstants.INPUT_MOVE_FORWARD,
|
|
GameConstants.INPUT_MOVE_BACKWARD
|
|
);
|
|
|
|
if (@event is InputEventKey eventKey && eventKey.Pressed)
|
|
{
|
|
if (eventKey.Keycode == Key.H)
|
|
{
|
|
MeshSwapper.NextHead();
|
|
}
|
|
|
|
if (eventKey.Keycode == Key.B)
|
|
{
|
|
MeshSwapper.NextBody();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|