- Home /
need to predict child position from a rotating parent (no gravity/physics)
So I've got a child that is offset from its parent and the parent has a basic script that makes it rotate slowly. In affect, a "fake orbit". No Physics or gravity turned on.
What I'm looking to do is find a way to predict the position of the child (the "planet"). I have seen some other posts about similar topics and there are some pretty advanced math answers... But I was hoping that since my fake orbits are all consistent and set by me, then there might be a simpler way to do this?
Anyway, If there isn't a simpler way, I guess I'll go back to the scary math answers and do my best to pretend I have a higher IQ than I actually do :/
Oh and, Im using c#
Thanks in advance.
Answer by FlaSh-G · Apr 04, 2018 at 12:44 PM
To not use any trigonometry or anything, you could put the rotation code in a method with a time parameter like this:
private void Rotate(float time)
{
transform.Rotate(Vector3.up * speed * time); // or whatever you use
}
Note that no Time.deltaTime is used.
Now, to use this method to re-implement the behaviour you already have, call it in Update with Time.deltaTime:
private void Update()
{
Rotate(Time.deltaTime);
}
At this point, you are where you are before. But now, you can use this method to look into the past or the future:
Rotate(20); // Go 20 seconds into the future
Debug.Log("The child will be at " + theChild.position + ".");
Rotate(-20); // Go back to the present
Your answer