- Home /
Show trajectory path a ball will take based on collision
I have seen ways to show the trajectory of a ball/object given a direction/velocity/angle such as when launching a projectile or throwing a grenade but those methods don't seem to take into account real time physics and/or not having a known or static starting/ending point.
I have a ball object and want to display its trajectory for two bounces meaning that I want to calculate and display the path it will take from the initial collision that gives the ball motion until the point where it collides with something else twice. The initial collision is collision 1, then the ball travels on an arc and collides with something else, which gives it a potentially new trajectory and the visualized path ends at the third total collision.
I understand I will need to use a line renderer and populate the points that it uses with a loop but I don't understand how to get the correct angle/direction of the collisions in question and my line renderer points in the wrong directions.
Essentially I want to have the result of a trail renderer for two bounces be shown when an object collides with the ball.
Answer by Waka-Takaki · Nov 24, 2018 at 10:04 PM
Have you considered creating a duplicate object collider without any renderer on it, and then "throwing" this the direction the ball will goes. It will use the physics engine, so you don't have to calculate anything yourself. To show the trail you can capture the position of the object every couple of frames and draw your line between the points. Then just destroy it once the object collides twice. If you don't want it to be slow you can increase the speed by increasing the physics speed with Time.timeScale.
I don't know if this is the best approach but I think it's a good one. So I'm upvoting this.