Predicting Unity Physics

Unity Physics Engine is such a gift!

You really wouldn’t want to write it by yourself. However, if you’d like to know in advance, where a GameObject will be a few Update()s later, you cannot rely on it completely. For our current development of Volley Brawl, we need to know how the ball (or bomb) is going to behave a few frames later, e.g. to be more precise about:

  • artificial intelligence (where should the computer player position next?)
  • audiovisual feedbacks (we have to know in advance about action potentials)


Luckily, Unity Wiki provides good examples for Trajectory Simulation. Nevertheless, we had to modify the code slightly to fit our needs.

Our changes:

  • Removed: the wiki solution uses a line renderer to draw the trajectory path
  • Changed: the collision layer can be set up via script
  • Added: trajectory is drawn as Gizmo
  • Added: the points are not accessible from outside the class
  • Added: the calculated points have an information about when the position will be reached in game time
  • Added: the calculated points yield information about the velocity
  • Added: dynamically refresh the path on collision/trigger and whenever there are too many points in the past

What still needs to be done:

  • The calculated bounce collision is not exact – no consideration of bounce materials
  • The predicted path after a simulated force has been added (for further artificial intelligence calculations)

Keep hacking,

Your Fantasy Arts Team

Share on FacebookShare on Google+Tweet about this on TwitterShare on TumblrShare on LinkedInEmail this to someone

Be the first to comment

Leave a comment

Your email address will not be published.