- Home /
Most efficient way to predict collision
Hi there! I faced tricky problem with vector maths. So I have constant velocity of both objects, renderers and their bounds. My problem is to calculate proper distance from ball to box that allows box to avoid collision. The way to check this objects for possible collision is also will be part of the solution.
You should just Raycasts for these things. Then you could just use the raycastHit.length
. Since this isn't what you were looking for probably I didn't post it as a answer
It may be useful if box were motionless. So I can use raycast in a loop but there can be more easier way to predict collision.
Get the velocity of the ball relative to the box, then it is a simple problem.
let the ball have velocity (x1, y1) and let the box have velocity (x2, y2), then in essence, the balls velocity relative to the box's, is (x1-x2, y1-y2), from there you can work out if the ball will collide given a particular position!