To detect collision with a projectile, is it better to use A Raycast or a primitive game object with the mesh renderer disabled? The raycast only detects collision with a single point where as using a cube or sphere will cover an entire area.
What i’m doing is putting a particle on top of the invisible cube and using the cube as trigger. Are there any draw backs with this method?
It’s actually no question what is better. It results in two different type of weapons (and there’s no difference in how many targets you can hit with one shot).
Weapons are divided into
- instant hit weapons (like you might know form counterstrike) that uses raycasts
- projectile weapons
The difference is that instant hit weapons will hit the object for sure if your cursor is over an enemy. Projectile weapons need time to travel. If you plan to build a instant hit weapon but you want also a visual projectile, use a raycast for collision and a gameobject without collider just for the visual effect.
To hit multiple targets with a Raycast you can use RaycastAll. It’s even possible to reduce the damage it does to the second, third,… target. You just need to sort all hits from nearest to furtherest.
Raycast will always work, but only with a single point. SphereCast always work. Using collusion detection is absolutely fine as long as things don’t move at very high speeds. If the speed is too high then the collider might be in front of the target on frame x and behind the target on frame x+1 without actually ever colliding.