Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

valkyrienyanko
Copy link

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