#How to restrict rotation that is based on Global Mouse Position?

1 messages · Page 1 of 1 (latest)

vernal ferry
#
func _process(delta):
    look_at(get_global_mouse_position())

This is the code I am currently using to make the lil pointer spin around. I want to make it so that the rotation cannot go under 0 or over 180, but my attempts just ended up with errors about Vector2D.

dense gate
#

In this situation, it may be easier to calculate the angle yourself, then clamp it to the range:

var change = get_global_mouse_position() - global_position
var angle = atan2(change.y, change.x)
angle = wrapf(angle, 0, 2 * pi)
rotation = clamp(angle, pi, 2*pi)

You may need to adjust the clamp range based on the pointer sprites default direction.

#

You could also potentially do:

var point = get_global_mouse_position()
point.y = min(point.y, global_position.y)
look_at(point)

Assuming look_at was giving you good results.

vernal ferry
dense gate
#

Sorry, try min, not max for the 2nd.

#

I forgot that up is negative.