+1 vote

Hello. I want my camera to rotate as the mouse moves. I tried putting a line
func process(delta)
get
globalmousepos()

but it just swirls my game non stop.
my vision for this is like the character is facing the mouse while he is in the middle of the camera (so like he is the screw in the middle of the camera (top down)

in Engine by (23 points)

1 Answer

+2 votes
Best answer

I'm not sure if this is exactly what you want, but you can rotate the camera towards the mouse pointer like this:

extends Camera2D

var center

func _ready():
    center = get_viewport_rect().size * 0.5
    set_process(true)
    set_rotating(true)
    make_current()


func _process(delta):
    var mouse_pos = get_viewport().get_mouse_pos()
    set_rot(-center.angle_to_point(mouse_pos))
by (1,562 points)
selected by

lemme try :)

Yes this is what I try to get. thank you so much :)

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.