- Home /
weapon sweep
i made a weapon script or my melee weapon and it work very well but there i something i want to change about it witch is instead of using raycast to hit a single enemy at a time i want to have a sweep effect meaning that all enemy in front of my character at a certain max angle and distance gets hit. so i want to know what is the best way to do it. please note that this is a fps and there is about 75-100+ enemy on the map at a time.
thank you for your time and help.
Answer by getyour411 · Mar 06, 2014 at 12:44 AM
Use Physics.OverlapSphere or one of the similar functions (CapsuleCast, SphereCast, etc), iterate through the collider[] return
https://docs.unity3d.com/Documentation/ScriptReference/Physics.OverlapSphere.html
yes but how can i check if he is in front of me because if i use Physics.OverlapSphere colliders behind me will still be affected
You control the 'center' of the sphere, so that doesn't have to be your player (which might pickup collider behind you); for example you could use the center as Vector3.forward + 2 (or some #) and use a small radius
Your answer
Follow this Question
Related Questions
Weapon pick up and switching script 2 Answers
Weapon swapping in-game 2 Answers
First Person Controller Collision Issues 1 Answer
How do you detect if two specific objects are touching. 1 Answer
making a named script update 1 Answer