cleaned controller code wich also makes controller stick directions work better

This commit is contained in:
2022-11-13 12:43:46 +01:00
parent 79a6e45bfb
commit 282d6d144c

View File

@@ -3,37 +3,20 @@ using System;
public class Player : KinematicBody2D public class Player : KinematicBody2D
{ {
private Vector2 velocity;
private Vector2 strength;
[Export] [Export]
public int speed = 400; public int speed = 500;
public override void _PhysicsProcess(float delta) public override void _PhysicsProcess(float delta)
{ {
GetInput(); MoveAndCollide(new Vector2
MoveAndCollide(velocity * strength * delta); (
} Input.GetActionStrength("move_right")
- Input.GetActionStrength("move_left"),
public void GetInput() Input.GetActionStrength("move_down")
{ - Input.GetActionStrength("move_up")
velocity = new Vector2(); ).LimitLength(1)
strength = new Vector2(Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left"),Input.GetActionStrength("move_up") - Input.GetActionStrength("move_down")).LimitLength(1).Abs(); * speed * delta
if (Input.IsActionPressed("move_left")) );
{
velocity.x -= speed;
}
if (Input.IsActionPressed("move_right"))
{
velocity.x += speed;
}
if (Input.IsActionPressed("move_up"))
{
velocity.y -= speed;
}
if (Input.IsActionPressed("move_down"))
{
velocity.y += speed;
}
} }
public override void _Process(float delta) public override void _Process(float delta)