- Home /
Diving NPC's out of the way (e.g., player avoidance)
I enclosed a picture to help describe the problem. Basically, I'm trying to figure out the best way to move my Pedestrian character (Pe) out of the way when my player (Pl) gets into collision range.
The only solution I have so far is that I add two blank GameObjects to my pedestrian, to the left and right of it. On collision with my player, I do a distance check between these blank GameObjects and player, and move the Pedestrian the opposite direction of the closest GameObject.
There has to be a more elegant soluition. Perhaps something with collision impact and normal?
Answer by whydoidoit · Jul 26, 2012 at 11:00 PM
I guess Vector3.Dot(transform.right, hit.normal) > 0 on the pedestrian's transform.right would tell you the the player was approaching from the right and you should go left, otherwise they are on the left.
So Vector3.Dot(Pedestrian.transform.right, hit.normal) > 0? I'm at the library so I can't test it right now, but for clarification? (I know this isn't how it would be coded, but for clarity)
Yes that should do it. Will tell you if the hit normal points to the same side of forward as right does.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074745im_/https://answers.unity.com/themes/thub/images/avi.jpg)