I’m wanting to make a game that has a mechanical a bit like Zelda.
When the player presses a button, he utilized the enemy as a target, and moved around over the enemy position. So if he moved to the sides, it would circle the enemy, and if he moved around up to or down, he would approach or move away from the enemy.
By pressing the button again, it would state Lock.
My problem is how to make this movement against the enemy’s position, anyone could give me any tips?
Thanks
Lock the camera position behind the player, write a function into the camera script for target selection, and then use Transform.LookAt in the camera script update function.
So your camera script would look something like this (a very simplified version):
var target : Transform
function Update ()
{
if (target)
{
Transform.LookAt(target);
}
}
function GetTarget ()
{
target = GameObject.FindObjectWithTag("Enemy");
}
As long as you make sure the camera is locked behind your player then you will be able to see both the enemy and the player. Then you just need to make sure your characters movement is determined from the camera’s point of view rather then world space.
You’d have to tweak the look at and camera position a bit however as this simplified version would mean that if an enemy is behind you your character would not be seen, only the enemy.