Hey all! I have used Unity for nearly 4 years now and I really do love it. Best engine I have used.
Jumping straight to it, what is the best method for detecting items in game?
Example scene:
Movable player,
NPC on a Nav Nesh.
What’s the least processor heavy, most accurate (as in detecting the player at a range AND from any direction), shortest code (without bunching it all together) and / or easiest to manipulate to multiple creatures (as in changing speed, how fast it notices you etc…).
The examples in which I know about all ready are:
_
1) Shooting Raycasts from the NPC to detect the player.
Advantage: Can control how fast it checks the cast meaning less processing,
fairly short code, easy to add to multiple creatures.
Disadvantage: Can only fire in certain directions, I.E forward, back etc… Meaning not very accurate. (Could be fixed focusing on the player only but would ruin anything to do with enemy NPC)
2) Adding a trigger to the character / NPC and checking in OnTriggerEnter and OnTriggerLeave for the other one to enter and leave.
Advantage: Fairly short code, easy to add to multiple creatures, fires in every direction.
Disadvantage: Can’t control how fast it checks.
3) Vector distance I.E taking player position from NPC position then using magnitude
Advantage: Easy to add to multiple creatures, fires in all directions and can control how fast it checks.
Disadvantage: Lots and lots of if statements and long code.
_
Is there any other methods? If not which of the three should be used when many NPC’s are spawned?
I don’t want anyone to write the exact code. Just the best method so I can code it myself.
Thank you for any assistance!