mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
Added strafing
This commit is contained in:
parent
d633618633
commit
60f2797541
2 changed files with 62 additions and 2 deletions
|
|
@ -29,6 +29,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
private Vector2 _movementDirection { get; set; }
|
||||
|
||||
private Vector2 _facingDirection { get; set; }
|
||||
|
||||
private Vector2 _rightStickInput { get; set; }
|
||||
|
||||
private Sprite2D _crosshair;
|
||||
|
||||
|
|
@ -42,6 +44,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
private GameManager _gameManager;
|
||||
|
||||
private bool _isStrafing { get; set; }
|
||||
|
||||
//private InventoryManager _inventoryManager;
|
||||
|
||||
public override void _Ready()
|
||||
|
|
@ -54,6 +58,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
|
||||
_movementDirection = Vector2.Zero;
|
||||
_facingDirection = Vector2.Zero;
|
||||
_rightStickInput = Vector2.Zero;
|
||||
_isStrafing = false;
|
||||
|
||||
_gameManager = GetNode<GameManager>("/root/GameScene");
|
||||
|
||||
|
|
@ -148,6 +154,14 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
{
|
||||
return Input.GetVector("left", "right", "up", "down");
|
||||
}
|
||||
|
||||
private Vector2 GetRightStickInput()
|
||||
{
|
||||
return new Vector2(
|
||||
Input.GetAxis("aim_left","aim_right"),
|
||||
Input.GetAxis("aim_up", "aim_down")
|
||||
);
|
||||
}
|
||||
|
||||
private Vector2 CalculateCrosshairPosition()
|
||||
{
|
||||
|
|
@ -165,10 +179,26 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
|||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_movementDirection = GetInput();
|
||||
if (_movementDirection != Vector2.Zero)
|
||||
_isStrafing = Input.IsActionPressed("strafe");
|
||||
_rightStickInput = GetRightStickInput();
|
||||
|
||||
// Update Facing Direction
|
||||
if (!_isStrafing)
|
||||
{
|
||||
_facingDirection = _movementDirection;
|
||||
if (_rightStickInput.Length() > 0.1f) // If the right stick is moved
|
||||
{
|
||||
_facingDirection = _rightStickInput.Normalized();
|
||||
}
|
||||
else if (_movementDirection != Vector2.Zero) // Fall back to movement direction
|
||||
{
|
||||
_facingDirection = _movementDirection;
|
||||
}
|
||||
}
|
||||
|
||||
// if (_movementDirection != Vector2.Zero)
|
||||
// {
|
||||
// _facingDirection = _movementDirection;
|
||||
// }
|
||||
Velocity = _movementDirection * (float)(Speed * delta);
|
||||
|
||||
MoveAndSlide();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue