Im currently with a project in development, an old-school doom-like fps, atm I’m using billboard shaders to render the enemies and objects, planes for the floor, ceiling and walls and cubes for objects (doors, buttons). The Doom’s billboards have 7 images, each for an angle, what I need is: Check the angle relative to the player’s current position.
Good reference. I can think of a few ways. Mathf.Atan2() will likely be the most efficient. First, you get a vector from the object to the player. Assuming each object is controlling its own texture it would be something like:
var dir = player.position - transform.position;
var angle = Mathf.Atan2(dir.z, dir.x);
if (angle < 0.0)
angle = angle + 360.0;
var index = Mathf.RoundToInt(angle / 45.0);
Note this is the angle on the XZ plane and disregards the ‘y’ component. I believe this is what you want. Also the index will go from 0 to 7 and, even if incremented by 1, the numbers will not line up with the number in the diagram. I think that 0 will line up with 7 and the numbers will increase counter clockwise, but you’ll have to play and see.