Camera rotates on mouse position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By timeofdeath12
:warning: Old Version Published before Godot 3 was released.

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

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)

:bust_in_silhouette: Reply From: mollusca

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))

lemme try :slight_smile:

timeofdeath12 | 2017-10-21 09:52

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

timeofdeath12 | 2017-10-21 10:01