DungeonRPG/Scripts/Characters/Player3D/Player3DDashState.cs

38 lines
946 B
C#

using Godot;
using System;
using DungeonRPG.Scripts.General;
public partial class Player3DDashState : PlayerState3D
{
private Timer timer;
[Export(PropertyHint.Range, "0, 20,0.1")] private float speed = 10;
public override void _Ready()
{
base._Ready();
timer = GetNode<Timer>("Timer");
timer.Timeout += HandleDashTimeout;
}
public override void _PhysicsProcess(double delta)
{
characterNode.MoveAndSlide();
}
protected override void EnterState()
{
characterNode.Velocity = new Vector3(characterNode.Direction.X, 0, characterNode.Direction.Y);
characterNode.AnimationPlayer.Play("sprint");
characterNode.Velocity *= speed;
timer.Start();
}
private void HandleDashTimeout()
{
characterNode.StateMachine.SwitchState<Player3DIdleState>();
characterNode.Velocity = Vector3.Zero;
}
}