+1 vote

I have a KinematicBody2D as the root node for my "Player" scene.

As a child of that node I have a Sprite node that I named "Weapon".

I need to have the weapon sprite always point to where the mouse position is but because it inherits that root node's rotation there is no way to make it face to the proper angle.

Even when I set the global rotation it will constantly snap back and forth to completely different rotations.

Is there any way to make it so a child node ignores its parent's rotation?

in Engine by (27 points)

1 Answer

0 votes

It's by design that a child inherits its parent's position, rotation, etc. That way a gun (child) can be pointed independently, but it will also change its direction if the player (parent) turns. The alternative would be to make them siblings in a parent container, where they could both work independently, but would both move/rotate with the container.

Regarding your specific problem with the "snap back and forth" when changing the rotation of your gun, you may be using degrees when your statement is expecting radians. Are you using set_global_rotdor set_global_rot?

Also, make sure you aren't confusing rotate (changes the rotation relative to the current rotation) with set_rot / set_rotd (sets the global rotation).

by (308 points)
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 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 webmaster@godotengine.org with your username.