- Home /
Predicting A Trajectory
Hi,
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
That sounds like what interpolation does for you. See here: http://unity3d.com/support/documentation/ScriptReference/Rigidbody-interpolation.html?from=RigidbodyInterpolation
Not sure if this is what you had in $$anonymous$$d though, or if you need direct access, so I'm leaving this as a comment.
No I don't need to interpolate the physics, I need to predict the physics before they happen. As in client side prediction I need the ability to rewind to a previous physics state, and resimulate the path that an object took.
I am having the same problem with a trajectory. It has been a year for you. Have you reached an answer?
Thanks in advance.
Good question. The global time scale affects all objects, so that is not a solution. Is this feature possible with PhysX? If not, Unity prob. won't get it either, since it builds physics on-top of PhysX.
Well, if you use unity's physics data to predict something using your own physics simulation, as long as it's only a few frames into the future and you are only doing it on specific, 'important' objects, the inaccuracies shouldn't be too bad, and the CPU overhead shouldn't be huge.
Answer by Joe 9 · Jan 06, 2012 at 12:56 PM
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.
Your answer
Follow this Question
Related Questions
Turn-based vehicle physics 1 Answer
2D projectile trajectory prediction 2 Answers
Calculating rigidbody top speed? 3 Answers
Networked Physics 0 Answers