Ok so I got this nice target lock on method made and it works pretty good. But now I want to allow the user to release the target lock, I really dont know how to do that with Unity.
if(Input.GetKeyDown(KeyCode.T))
{
//look at target
var newTarget = GameObject.Find("Ninja").transform;
GetComponent(Follow).target = newTarget;
print("Lookng at ninja");
}
Should I set the target to null if the button is pressed again or another button is pressed?
Ninja, surely that’s a design decision that will be down to the control scheme you decide to adopt for your project. Either options sounds plausible, just depends on how you want your game to work.
Ok so I got the gameobject to stop looking at the ninja, but now when I hit the relase toarget button it seams to invert the movement commads I.E. when I press the w key it move forwad but after I preass the release key the w key moves side ways. Did I break the game engine or something?
if(Input.GetKeyDown(KeyCode.T))
{
//look at target
var newTarget = GameObject.Find("Ninja").transform;
GetComponent(Follow).target = newTarget;
print("Lookng at ninja");
}
if(Input.GetKeyDown(KeyCode.R))
{
GetComponent(Follow).target = null;
print("ORO");
}
Nothing seems wrong there. Can you post the Follow script (or link to it if it’s publicly available)?
Here is the follow script
var target : Transform;
function Update () {
transform.LookAt(target);
}
I started to think maybe there is nothing wrong and the player gameobject is just at a different angle or something and it just looks like the input is messed up or something.