0 votes

So im making a top down shooter and Im trying to make the player's camera move with mouse movement. For this I tried $Camera2D.offset = get_local_mouse_position() and it gave results closest to my desired effect, but whenever I move my mouse to the left side of the screen, the camera gets pushed to the right which is what I dont want. I tried many other methods but changing the camera's offset is best for my game. Is there a way to fix this so that way the camera goes to the left as it should.

Godot version 3.2
in Engine by (25 points)
edited by

You can hide your question

1 Answer

+1 vote
Best answer

Do you need a camera that follows?

$Camera2D.position = linear_interpolate(get_global_mouse_position()

If not then can you elaborate more of what your desired effect so we can understand

by (386 points)
selected by

Apologies for being a little less descriptive. Ill edit the post have a bit more detail on the post. But also, there is no linear_interpolate() function in godot as default or defined in my code. Can you give me a better solution?

Ok this is much more easier:

$Camera.position = get_global_mouse_position()

and then in your camera, go to Smoothing and turn it on.
it's up you whenever you'll experiment on this one


I tried it in my test and if you want a camera that follows player at the same time pan in your cursor a little bit

change the code above to :

$Camera.position = get_local_mouse_position()

Thanks! Youre being a big help, but one more thing. Is there a way to set up a limit for how far the camera can go towards the mouse until stopping? When ever I do play around with the second code snippit you gave me, the camera goes way to far for my liking, and always want to make it where the players stays in view with a slight pan based off of local mouse position.

Lol brother, you must learn how to solve your own problem as a programmer. Either way, replace get_local_mouse_position to $Camera2D.get_local_mouse_position

No worries brother, Im not gonna be completely dependent on the internet. I only really try to use forums like these as a last resort when I cant find something out. But It works as expected. Thank you very much and have a great day/night.

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.