- Home /
2D sprite that always faces the player?
Im building a horror game that is sort of voxel based, and i wanted to make the enemies and NPCs in a 3D environment game always face the player like in old FPS games like duke nukem 3D and DOOM, but only along the Y axis so they dont do that strange visual artifact if you are on a higher plane then they are. Im not sure how to do this, any help would be wonderful.
Answer by robertbu · Feb 02, 2014 at 01:25 AM
It is not clear how you want his billboarding to work. The visible side of a sprite is the back, so I'm going to assume you want the back of the sprite to face the camera. And that you only want to rotate around the 'y' axis. One way to enforce only rotating around the 'y' axis is to remove any 'y' component from the calculated vector. The code will be something like:
var v = transform.position - Camera.main.transform.position;
v.y = 0.0;
transform.rotation = Quaternion.LookRotation(v);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Script gives wrong rotation. 1 Answer
Camerascript works strange! 0 Answers
Wall Jump script 2 Answers
2D object look at 3D object 0 Answers