- Home /
Is there a way to predict a rigidbody's drop point ?
I have a rigidbody it is ball with velocity and gravity and i want to predict its drop point cause im trying to make an ai to go to its drop point. is there a way to do that ?
Answer by Cuttlas-U · Sep 10, 2017 at 06:44 AM
hi; u shoud use :Physics.Simulate() ;
there is a good tutorial for it here :
I tried watching it sir but i think its a little too complicated for me sorry sir but i see he's using the Physics.simulate to simulate a scene without even pushing the play i think ?? i dunno
what i want is when the ball collide with some object and a change in velocity has occurred i want to simulate the drop then is there a way to do that ?
Well, the physics system is quite complicated. If you use any kind of drag on the object it becomes almost impossible to predict / precalculate where an object might be after X time. The easiest way is to do it like this:
Save the state of all rigidbodies so you can reset them to the current state later. This includes the position, rotation, velocity and angularVelocity.
Run Physics.Simulate in a loop until your desired time has passed or a certain event has happened (trigger / collision)
Finally just reset the scene to the saved state.
All this would happen during one frame. So everything would keep run normally the next frame. Of course this can't / shouldn't be done every frame especially if you want to look far into the future.
The nice thing is this will correctly deter$$anonymous$$e what will happen, even the collsion of multiple moving objects. Of course it can't take user actions into account that might happen in between (depending on the control the player has).