- Home /
How do I get the 3d position that an object is looking at?
I have a dungeon type game, and i put the camera behind my player when he comes up to an enemy. The problem is if my player comes in on an angle his back is to a wall and the camera will be behind the wall.
My solution to this is that if the player comes up to an enemy, i want to move his position to be directly in front of the enemy, with a specific distance between them.
So, how can i figure out from my enemy.transform a position N pixels away from where the enemy is looking?
Answer by Andres-Fernandez · Feb 04, 2015 at 07:54 AM
Then just apply the distance to the forward vector of the enemy and add it to the enemy position:
player.transform.position = enemy.transform.position + enemy.transform.forward * distance;
Answer by Reeceg · Feb 04, 2015 at 07:55 AM
var distance = Vector3.Distance(player.transform.position, enemy.transform.position);
You could also give the camera a collider.