RigidBody collision prediction

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By toxicrecker

In my game balls are thrown in towards the player by a turret. How can I make it so that if the player is ball’s path a text is displayed on the screen? Newbie here, thanks in advance.

:bust_in_silhouette: Reply From: DaddyMonster

Is the turret also moving?

If so

How good is was your maths teacher? The rigorous way is to solve for the intersection vector through a series of linear equations using a iterative implementation of Gaussian elimination. Khan Academy covers it well but this is not a beginner’s approach.

Otherwise, you can always just simulate. Every ten frames or so you could (asynchronously on a thread if you can) loop the movement and test if they get close enough to collide.

Otherwise, I can’t think of an easy beginner way, sorry.

If not

Cast a raycast pointing in the forward velocity vector of the ball and and it’ll tell you if it intersects with the turret.