Hi, I currently have a working turret thats working fine, its able to turn and calculate the angle needed perfectly. However my problem now is I want it to only shoot if the trajectory of the bullet is clear and not blocked. I’ve tried raycasting but it doesn’t account for the curve in the path due to gravity, which means sometimes the bullet is blocked but the raycast is clear and vice versa.
I’ve taken some screenshots to illustrate:
The green line is a direct raycast to the target and the blue lines are raycasts off the direction of the barrel and turret base.
So in the first picture the path is blocked but no raycasts are hit while in the second picture the raycasts are blocked but the path is clear. Basically I want the turret to stop shooting in picture 1 but continue in picture 2.
So how could I test if the trajectory of the bullet is blocked or not?
For some extra info heres the script which I’m using to fire the bullet.
Its pretty standard where the angle and speed have both been calcuated, and the bullet is just a standard rigidbody.
var instantiatedProjectile = Instantiate(projectile,barrel.position,barrel.rotation); instantiatedProjectile.velocity=barrel.TransformDirection(Vector3(0,0,speed));