i know exacly the kind of procedure i got to do.. i just dont know the coding ..

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

but how can i do this math?

dot product of players forward vector with vector from player to enemy

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…

maybe if use quaterniom.lookdirection

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
	}
	
}

it works perfectly

i never heard of this dot product code… when JRavey first mentionated i tough he was refering to product.product
lol

anyway… thanks a lot!.. i think is about the fifty time you helped me

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.

true… in 2D all you have to do is turn facing right true and facing left false… vice versa ehehe…

and also check if the boo is positionated at + X or - X based on your axis … good old times 2D games ruled =D

thanks for the tip man !