folks… i realy need help with this one… i design this enemy in my game that only attacks the player when he is not facing him… he only attacks behind his back
now… the procedure to do this … i belive is to check if the enemy rotation is 180° degres diferent from the player’s rotation
Oh, so this is like a Boo in Super Mario Brothers? Wouldn’t it be that they should both be facing the same direction for the Boo to move towards your protagonist?
Also, this is important, is your game a 2D or 3D game?
if is not ask too much… could you write a small example of this code?.. my bigest problem is not beein aware of the coding
its a 3D game… and yea! he is like a boo of super mario games… with a small diference … when you face him ,he gets cautch in surprise and it takes a little long to defend himself… so thats the window you have to attack him
but… i think you’re right… maybe it will be easier to just check if they’re both looking at the same direction…
You want to use dot products, like pakfront mentioned.
Here is a very basic usage to get you started (put this on the AI boo guy, and make sure the player var gets populated, whether you drag the player object to the var in the inspector or find set it in Start() via Find/FindGameObjectWithTag):
var player : Transform;
function Update(){
var myForward = transform.forward;
var playerForward = player.forward;
var dotProduct = Vector3.Dot(myForward,playerForward);
if(dotProduct < -0.8){
//The player and I are directly facing each other
}
}
The reason I asked about the 2D/3D bit is that unless it is 2D, getting the angles as precise as 180° is not practical. In a 2D game, the facing is purely binary most of the time, except in special game-specific cases.