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:
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.