0
\$\begingroup\$

I've got an object that has a comet-like sprite rotating around it. I'm using this code in LateUpdate() to make it rotate and keep the comet's tail at the right position:

transform.position = player.transform.GetChild(0).transform.position + (transform.position - player.transform.GetChild(0).transform.position).normalized * 2f;
transform.RotateAround(player.transform.GetChild(0).transform.position, Vector3.forward, 100f * Time.deltaTime);

It works fine until the object moves. After moving, the comet follows the object and goes back to the orbit, but its rotation gets messed.

I've got an image describing this problem: enter image description here

The image on the left shows how the comet behaves at the beginning. On the right there's a sample of how the comet's position can possibly look after moving around. I want it to always look like on the left image.

Is there any way to stick the comet to the object's orbit? It can move as fast as the object, I don't need tealistic calculations of the position changing for the comet.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Ok, I managed to solve this problem. I removed all the code posted above, made a new empty object (called rotationAxis) as the main object child and put the comet into the rotationAxis object 2f units from the center. After that, I just rotate the rotationAxis object with this code in Update(): transform.Rotate(0f, 0f, 3f, Space.Self);. Now, it's sticked to the player and does not lose it's own rotation.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .