- Home /
NPC Transform.Direction relative to player??
Hi,
I'm currently setting up an AI to control vehicles.
My script compares speed, position, distance amongst other parameters, but I'm now stuck with the player direction relative to NPC.
The script knows when the player is in front of NPC, but in addition to this I need to know if the player is currently facing the NPC or not... The NPC would be happy to know that, then it would choose between different actions and I guess the NPC will feel more... smart ;°)
So I tried with Transform.Direction and get an usefull value but I can't rely on it when the NPC changes it direction...
Thanks in advance for the quick hint on this!
here is a sum of my script in c#
public Transform myTransform;
public Transform vTarget;
public Vector3 myDir;
public Vector3 vDir;
public float vDirZ;
void Update()
{
myDir = myTransform.InverseTransformDirection(Vector3.forward);
myDir.Normalize();
vDir = vTarget.InverseTransformDirection(Vector3.forward);
vDir.Normalize();
vDirZ = myDir.z - vDir.z;
if ( vDirZ >= ???)
DoSomething;
}
// Edit // No moderator today? Many hours since I posted this question now, and til waiting for approval... Hum... well, finally I temporary solved the case with a Vector3.Dot... but just in case, if anyone has a better formula. Bye.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
[C#] Raycast based AI 2 Answers
AI positioning in soccer game 1 Answer
C# Script Not Working? 2 Answers