mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-22 19:43:55 +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 _movementDirection { get; set; }
|
||||||
|
|
||||||
private Vector2 _facingDirection { get; set; }
|
private Vector2 _facingDirection { get; set; }
|
||||||
|
|
||||||
|
private Vector2 _rightStickInput { get; set; }
|
||||||
|
|
||||||
private Sprite2D _crosshair;
|
private Sprite2D _crosshair;
|
||||||
|
|
||||||
|
|
@ -42,6 +44,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
|
|
||||||
|
private bool _isStrafing { get; set; }
|
||||||
|
|
||||||
//private InventoryManager _inventoryManager;
|
//private InventoryManager _inventoryManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
|
|
@ -54,6 +58,8 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
|
|
||||||
_movementDirection = Vector2.Zero;
|
_movementDirection = Vector2.Zero;
|
||||||
_facingDirection = Vector2.Zero;
|
_facingDirection = Vector2.Zero;
|
||||||
|
_rightStickInput = Vector2.Zero;
|
||||||
|
_isStrafing = false;
|
||||||
|
|
||||||
_gameManager = GetNode<GameManager>("/root/GameScene");
|
_gameManager = GetNode<GameManager>("/root/GameScene");
|
||||||
|
|
||||||
|
|
@ -148,6 +154,14 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
{
|
{
|
||||||
return Input.GetVector("left", "right", "up", "down");
|
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()
|
private Vector2 CalculateCrosshairPosition()
|
||||||
{
|
{
|
||||||
|
|
@ -165,10 +179,26 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
_movementDirection = GetInput();
|
_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);
|
Velocity = _movementDirection * (float)(Speed * delta);
|
||||||
|
|
||||||
MoveAndSlide();
|
MoveAndSlide();
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,36 @@ Use={
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
aim_right={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194444,"key_label":0,"unicode":54,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
aim_left={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194442,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
aim_up={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194446,"key_label":0,"unicode":56,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
aim_down={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194440,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
strafe={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue