- Home /
Trouble with Projectiles, Raycasting, and 'Gravity'
I've currently got a setup where my projectiles raycast out in front of themselves by their current velocity in their forward direction to check to see if they will hit anything [so quite a common setup]. I'm also 'faking' gravity through script since the physics system isn't able to reliably catch collisions at the speed my projectiles are traveling.
My setup mostly works, however it has a real problem with collisions that happen at shallow angles...Notice in the attached picture a red and yellow line (red being the 'first' raycast and yellow being the 'second'). What you can't see is that in between these lines is a collider, and unfortunately the raycasts missed it because the projectile 'dropped' just enough in 1 frame to pass through it.
I'm wondering if anyone has taken a shot at resolving this sort of problem before, and what your conclusion was. Off the top of my head the only 'good' idea I've got is to also do a linecast each frame from the current projectile location to the previous one and check for an intersection. Which I suppose should work, though the accuracy of the point that was hit could be very questionable...
I'm also working on a mobile platform right now, so doing some sort of 'breakdown' each frame where the distance traveled is broken down into a series of smaller 'parabolic arc steps' I don't think would be practical.
Any ideas are appreciated, thank you for reading.