added joystick strentgh to player speed and diagonal movement isn't faster anymore

This commit is contained in:
2022-11-13 02:33:55 +01:00
parent 226f5d150c
commit ba2653491e
2 changed files with 7 additions and 5 deletions

View File

@@ -4,18 +4,20 @@ using System;
public class Player : KinematicBody2D
{
private Vector2 velocity;
private Vector2 strength;
[Export]
public int speed = 400;
public override void _PhysicsProcess(float delta)
{
GetInput();
MoveAndCollide(velocity * delta);
MoveAndCollide(velocity * strength * delta);
}
public void GetInput()
{
velocity = new Vector2();
strength = new Vector2(Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left"),Input.GetActionStrength("move_up") - Input.GetActionStrength("move_down")).LimitLength(1).Abs();
if (Input.IsActionPressed("move_left"))
{
velocity.x -= speed;
@@ -32,6 +34,10 @@ public class Player : KinematicBody2D
{
velocity.y += speed;
}
if (Input.IsKeyPressed((int)KeyList.F1))
{
GD.Print(strength);
}
}
public override async void _Process(float delta)