Predicting A Trajectory


I need to be able to predict the trajectory that a rigidbody will take for client side prediction, as such I can't create an invisible object and then collect the data, as it needs to be calculated as quickly as possible.

Is there any way built in to fake a physics timestep on a particular rigidbody? Or will I need to roll my own?

Cheers J

In the end I managed to just about get everything I needed by attaching a charactercontroller to an object, rolling my own basic rigidbody script using the equations of motion, namely s = ut + 0.5at^2, and then updating velocity with v = u + at. Then I move the charactercontroller with the move() function, and process collisions in OnControllerColliderHit().

It’s far from ideal, and means I have physics limited to what I implement myself in OnControllerColliderHit(). I also use this new rigidbody script as a replacement for the unity one, as this will certainly disagree with PhysX when any kind of complicated collisions happen.

For anyone interested, I needed to do this for a rewind-and-replay client-side prediction algorithm for a multiplayer FPS. I’ve come to realise that at present, Unity probably isn’t a suitable engine for a multiplayer FPS which requires a robust networking model.

One possible way to do this would be to compile an existing physics engine (e.g. the excellent and open-source Bullet physics SDK) into a plugin, it would take a fair amount of work, and I have no idea how well it would perform what with passing data between unity and the plugin, but it’s the only decent solution I can think of.