- Home /
Cone of effect weapon FPS
I'm looking to make a flashlight weapon for an fps. Basically, I want it to affect a cone in front of the player but only in line of sight. The enemies have weak spots that you have to hit. My idea was to use an invisible cone to detect if anything was inside of it and then use a raycast to see if they were in line of sight. However, I'm running into some problems.
I've found that using onCollisionEnter is only used for rigidbodies and so doesn't seem to apply.
OnTriggerEnter can't be used for moving objects.
My idea then was that when the player pushed the 'fire' button I would instantiate the cone and use OnTriggerEnter to gather up all the objects that intersect with it and then raycast to see is those objects are in line of sight. I just have no idea how to actually do that. Please help.
You can use Physics.OverlapSphere and check for the angle.
That looks like exactly what I need, thank you. Now how would I check for the angle?
if ( Vector3.Angle( targetPosition - myPosition, myForward ) < flashlightSpread ) TargetInRange();
Awesome. I just googled it too and found Vector3.Angle. I'm a total noob and this is super helpful. Thank you.