Ambiera ForumDiscussions, Help and Support. 




I want to create Doom style sprite. How do we get the angle between the enemy facing direction and the player position in JavaScript? Thank 


If you want the sprites to always face the player simply use the inbuilt billboard  which will always face the player. 


Thank, but I also need to view it form different angle (8 direction), so probably need some math here. I have take a look at "8 direction sprite" action by Just in case and it's seem what I need, but it work a little weird, maybe need a little tweek. Also "look at target" behaviour does have some math about angle and rotation. 


I think you just need a normilized angle between camera and your enemy rotations. So you get rotations first: var camRot = ccbSetSceneNodeProperty(camNode, 'Rotation'); var enemyRot = ccbSetSceneNodeProperty(enemyNode, 'Rotation'); then calculate the difference. since y axis is up you only need it: var diff = enemyRot.y  camRot.y; //normilize, so it's always between 0359 degress: diff = (diff % 360 + 360) % 360; //now you pick an animation based on this diff value: if (diff >= 330  diff < 30) { // .. forward } if (diff >= 30  diff < 60 ) { //.. rightforward } and i.e. 


Thank, I'll give it a try. 


Use Pythagoras' theorem for find angle between two points, i always use it and this theorem help find distance to. 


so i create function like this:
or
i know this code based on 2dimensional space but it's totally do what i need, return angle between 2 object, i made it by myself so you can find some better way. "Thank, but I also need to view it form different angle (8 direction), so probably need some math here." you can setup direction of enemy then check angle to player and change texture to one of your 8 image P.S. there is one drawback, the angle is returned in the range from 90 to 270
add this and from 0 to 360 
