0 votes

Hello, I'm trying to create a camera for a little editor (A camera that you can move using the mouse wheel), It moves using the position of the mouse when is pressed the middle button of the mouse, but when I try to move it it goes back to it's initial position.

This is the code:

public override void _UnhandledInput(InputEvent @event)
    if (@event is InputEventMouseMotion mouseMotion)
            if (Input.IsActionPressed("middle"))
                double delta = GetProcessDeltaTime();
                GlobalPosition = -GlobalPosition.Lerp(GetGlobalMousePosition(), 2 * (float)delta);

Here is a video of the problem:

Godot version v4.0.beta7.mono.official [0bb1e89fb]
in Engine by (64 points)

1 Answer

+1 vote
Best answer

I think the problem is in the GlobalPosition = -GlobalPosition... You are negating the coordinates every frame. Remove the minus sign, and it should work :)

by (1,100 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 Frequently asked questions and 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 [email protected] with your username.