cirnogodot/Scripts/PlayerMovement.cs

40 lines
718 B
C#
Raw Normal View History

2024-02-26 08:33:37 +01:00
using Godot;
using System;
public partial class PlayerMovement : CharacterBody2D
{
[Export]
public int Speed { get; set; } = 400;
private AnimatedSprite2D _animatedSprite;
public override void _Ready()
{
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
}
/*public override _Process(float _delta)
{
if (Input.IsActionPressed("ui_right"))
{
_animatedSprite.Play("run");
}
else
{
_animatedSprite.Stop();
}
}*/
2024-02-26 17:35:40 +01:00
public Vector2 GetInput()
2024-02-26 08:33:37 +01:00
{
2024-02-26 17:35:40 +01:00
return Input.GetVector("left", "right", "up", "down");
2024-02-26 08:33:37 +01:00
}
public override void _PhysicsProcess(double delta)
{
2024-02-26 17:35:40 +01:00
var inputDirection = GetInput();
Velocity = inputDirection * (float)(Speed * delta);
2024-02-26 08:33:37 +01:00
MoveAndSlide();
}
}