Sneak detection

I would like to add something like TES sneaking, where getting close to enemies and depending on whether you are in front or behind deterimes whether youve been detected or not. I was thinking of multiple triggers but i was told unity doesnt support multiple triggers, so I’m a bit stuck on where to begin and what to implement. Any Suggestions?

I can help you out, if you explain abit more what you want to do and how you want it to be done.

You can add me on skype if you like to talk there, instead of posting here.

Skype: marius.alexander.winsjansen

Just add a trigger on the enemy transform (as a child), something like a “Torus” prefab in Cheetah3D and use collision detection to know when you are close enough :wink:

Using a vector dot product between the enemies view vector and vector between enemy and player can tell you if they can “see him” by being within a certain angle. It is also fast to calculate.

Yeah, but he wanted to know if you are in front or behind the enemies, so he might whant to do something else. The point is to not get cought, am I right? and you are getting cought before you collides whit it, so then on trigger is never going to be triggered.

But, I might have the idea wrong, of what he is looking for thought! :slight_smile: hehe

Ok what I would do is have a field of vision for the enemy, if the player is not within that field then he must be behind the enemy. Then do some Vector3.Distance to calculate how close the player is.

BFGames posted the most appropriate solution for in front/behind detection…

The code example is even for in front/behind…

I would use this in conjunction with Physics.SphereCast

Sorry was on my phone when I first posted the question. Let me re explain now lol.

I want to implement a sneak feature like the one used in the Elder Scrolls games. Basically when you are crouched (sneaking) you are able to sneak up behind enemies sometimes undetected depending on how you approach the enemy. If you sneak up behind you can reach the enemy undetected to perform a sneak attack, on the other hand if you were to sneak up in front you would be seen obviously. Although I don’t want it to be 100% success if you come up from behind cause I want to add a sneak skill an make your success dependent on that as well.

Field of vision sounds good, but how would I add the detection chance from behind?

Okay, thanks for the link.

um unity does support as many triggers as you need. Whoever gave you that advice needs to be ignored regarding unity for all eternity.

Haha +1

I could see how someone unlearned could form that opinion since its one collider per gameobject

Well you could use the dot product to check vision as i said earlier. And then check for the players skill level and use random to check. Lets say you can have from 0 to 40 in skill level, then maybe random.range(0, 100), and then check if(50 + skilllevel < random) then you go undetected. This will give you a basis of a fifty/fifty chance and give you up to a 90% chance to go undetected when you master the skill. Just sn example, but the idea could probably be used.