The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

Hello!

I would like create a node around an other, rotatable node. I know the direction and distance (e.g.: 50 pixels) and I would like the XY coordinates on basis of these.
This is the piece of code in player1 node:

player2.position.x=position.x+50*cos(rotation_degrees)
player2.position.y=position.y+50*sin(rotation_degrees)

I have similar problem like this:
https://godotengine.org/qa/50695/rotate-object-around-origin
but I can't set the center of rotation to player1 positions. So, the player2 always orbits around itself but I would like similar a bullet creating at the cannon barrel or a planet around a star.

Godot version 3.3 Stable Official Win64
in Engine by (52 points)

1 Answer

+1 vote

Use a position2d node as the root of your scene instead(This will serve as the origin of the scene). Add your player giving them the offset you need from the origin. Now when you rotate the scene it will rotate around the desired origin.

by (2,018 points)

Thanks, Magicalogic, but I would like avoid using of Position2D node if possible and use some calculations instead of that, because the size of sprite may be different, which emit this other node.

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.