0 votes

Hi i made script to make camera movable by mouse wheel but when i tried move camera by my middle mouse button camera move out of main scene so here is my question how can i set my camera speed? Under i give my simple script

bool move

public void MoveCamera(InputEventMouseButton eventMouseButton, InputEvent @event)
{
    if (eventMouseButton.ButtonIndex == (int)ButtonList.Middle && @event.IsPressed())
    {
        move = true;
        mouse = GetLocalMousePosition();
    }
    else
    {
        move = false;
    }
}

public void MoveCamera()
{
    if (move)
    {
        GlobalPosition = (GlobalPosition + mouse);
    }
}

public override void _Process(float delta)
{
    MoveCamera();
}
in Engine by (74 points)

1 Answer

+1 vote
Best answer

Create a new float variable for the speed.

[Export]
float speed;

public void MoveCamera()
{
    if (move)
    {
        GlobalPosition += mouse*speed;
    }
}
by (3,227 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.