The rotation locked in a range

Godot Version

4.3 .net

Question

` I have maked a script of the RigidBody2D have a constant velocity and can rotate facing the mouse. But when it runs, the rotation seems like be locked in a range.
heres the code:
extends RigidBody2D
func _ready() → void:
pass
func _process(delta: float) → void:
linear_velocity = Vector2(10, 0)
rotation = rotate_toward(rotation, (get_global_mouse_position() - position).angle(), delta * 8)


image

`

What is the range it’s locked in? The code looks fine at a glance, what is going wrong?

if i add a camera to the children of the RigidBody, the problem is magically solved, but if i did it to another RigidBody, it will be locked again

and if i did rotation += -PI / 4 in _process, it will be locked to 90 degrees up, seems like the rotation is reseting again and again

Do you get the same result if you try it on something that isn’t a RigidBody?

It might be be because RigidBodies aren’t supposed to have their position and rotation updated directly. There’s some information about in the docs (Using RigidBody — Godot Engine (stable) documentation in English) and, to my surprise, an example that I think might be a solution to your exact problem!

3 Likes