💄 Optimize movement
This commit is contained in:
@@ -6,21 +6,24 @@ namespace AceFieldNewHorizon.Scripts.Entities;
|
|||||||
public partial class Player : CharacterBody2D
|
public partial class Player : CharacterBody2D
|
||||||
{
|
{
|
||||||
[Export] public float Speed = 400.0f;
|
[Export] public float Speed = 400.0f;
|
||||||
|
[Export] public float RotationSpeed = 3.0f;
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
// Get direction to mouse and calculate angle
|
// Get direction to mouse and calculate angle
|
||||||
var mousePos = GetGlobalMousePosition();
|
var mousePos = GetGlobalMousePosition();
|
||||||
var direction = GlobalPosition.DirectionTo(mousePos);
|
var direction = GlobalPosition.DirectionTo(mousePos);
|
||||||
Rotation = direction.Angle() + (float)Math.PI / 2;
|
Rotation = direction.Angle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
// Get movement input
|
// Get movement input
|
||||||
var inputDirection = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
var moveForward = Input.GetActionStrength("move_up") - Input.GetActionStrength("move_down");
|
||||||
Velocity = inputDirection * Speed;
|
|
||||||
|
// Calculate movement direction based on rotation
|
||||||
|
Velocity = Vector2.Right.Rotated(Rotation) * moveForward * Speed;
|
||||||
|
|
||||||
MoveAndSlide();
|
MoveAndSlide();
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user