I’m attempting to have a turret fire at an enemy and have the bullet go through that enemy and hit any enemy behind it. The aiming and the animation are handled but I’m having difficulty determining the best way to detect the objects that the bullet or ray should hit.
A raycast ends as soon as it intersects an object and a linecast returns boolean. I’ve searched and am at a loss on this. Pointing me to the correct function is all I’m looking for.
You might try making the bullet a trigger and have to ships send a message back to the bullet when it collides with them. Once the bullet has receive two messages, it will be destroyed. Or, if the ships don’t require that the be able to collide with anything, you could make them be triggers. You could use function OnTrigger() for the bullet, and when the bullet has hit two triggers, destroy it.
Thanks for the reply CgRobot. I wish I could do it that way but I am trying to avoid physics-based collisions since bullets often miss, and I don’t want my towers to, and if I make the bullets move too quickly, collisions won’t always register. I’m looking for a nice gauss rifle-type effect.
I was thinking about creating another raycast from the far side of what I hit, but that gets to be difficult if monsters are on top of eachother, which is where the turret is most useful.
Could I possibly instantiate an non-rendered cube and gather all the colliders from it?
Have you thought of simply making a physical bullet with a long collider and have it go through space over the course of 2-3 frames. If it hits a target it will register a collision, if it hits a wall or something that it cannot damage (or goes past a certain point) destroy it.
So have a box that travels x distance then you scale it from the starting point and place it in it’s shot vector and make it larger as you go. It is like scaled (0.1, 0.1,distance) Apply that to an set of cylinders half that distance and placed 3/4 of the way to the target to get the effect that you want. This way, you get a Railgun effect, a long collider for multiple hits and you could progress it all in like 0.25 seconds and make it really fast.