Skip to content

Only allow one method of moving the player at a time#1

Open
valkyrienyanko wants to merge 1 commit intosultansagitov:mainfrom
Valks-Forks:main
Open

Only allow one method of moving the player at a time#1
valkyrienyanko wants to merge 1 commit intosultansagitov:mainfrom
Valks-Forks:main

Conversation

@valkyrienyanko
Copy link
Copy Markdown

Before you would be able to combine both keyboard and mouse movements to move twice as fast. This PR restricts this so only one method may be used at a time. That is keyboard or mouse but not both.

Before

Velocity =
    new Vector2(
        Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left"),
        Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up")
    ).Normalized() * Speed;

if (Input.IsActionPressed("mousedown"))
{
    var direction = (mouse / main.camera.Zoom) - Position;
    if (direction.Length() > 1f)
        Velocity += direction.Normalized() * Speed;
}

After

if (Input.IsActionPressed("mousedown"))
{
    // Move player by mouse
    var direction = (mouse / main.camera.Zoom) - Position;
    if (direction.Length() > 1f)
        Velocity = direction.Normalized() * Speed;
}
else
{
    // Move player by keyboard or controller
    Velocity = new Vector2(
        Input.GetActionStrength("ui_right") - Input.GetActionStrength("ui_left"),
        Input.GetActionStrength("ui_down") - Input.GetActionStrength("ui_up")
    ).Normalized() * Speed;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant