Adjusted movement and included collider collisions as a constraint to the player
This commit is contained in:
@@ -2,7 +2,7 @@ using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
public partial class Player2D : Node2D
|
||||
public partial class Player2D : CharacterBody2D
|
||||
{
|
||||
[Export] private float _speed = 100f;
|
||||
[Export] private AnimatedSprite2D _sprite;
|
||||
@@ -15,7 +15,8 @@ public partial class Player2D : Node2D
|
||||
|
||||
if (Input.IsActionPressed("move_right"))
|
||||
{
|
||||
Position = new Vector2(Position.X + (_speed * (float)delta), Position.Y);
|
||||
Velocity = new Vector2(_speed, 0);
|
||||
MoveAndSlide();
|
||||
_sprite.FlipH = false;
|
||||
_sprite.Animation = "side_walking";
|
||||
anyActionPressed = true;
|
||||
@@ -23,7 +24,8 @@ public partial class Player2D : Node2D
|
||||
|
||||
if (Input.IsActionPressed("move_left"))
|
||||
{
|
||||
Position = new Vector2(Position.X - (_speed * (float)delta), Position.Y);
|
||||
Velocity = new Vector2(-_speed, 0);
|
||||
MoveAndSlide();
|
||||
_sprite.FlipH = true;
|
||||
_sprite.Animation = "side_walking";
|
||||
anyActionPressed = true;
|
||||
@@ -31,14 +33,16 @@ public partial class Player2D : Node2D
|
||||
|
||||
if (Input.IsActionPressed("move_up"))
|
||||
{
|
||||
Position = new Vector2(Position.X, Position.Y - (_speed * (float)delta));
|
||||
Velocity = new Vector2(0, -_speed);
|
||||
MoveAndSlide();
|
||||
_sprite.Animation = "back walking";
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
if (Input.IsActionPressed("move_down"))
|
||||
{
|
||||
Position = new Vector2(Position.X, Position.Y + (_speed * (float)delta));
|
||||
Velocity = new Vector2(0, _speed);
|
||||
MoveAndSlide();
|
||||
_sprite.Animation = "front walking";
|
||||
anyActionPressed = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user