Hi Everyone,
This is my first post I really new to unity and love it already. With that said I have a problem I have I’m trying to lock on to an object when it touched. I have been able to use lookAt() to rotate to the object when touched but when the object moves i can’t follow it untill I touch it again. What I’m look to to is creat an auto lock where once the object is touched it follows it.
Any help would be great.
Thanks
kcarriedo
you need to use lookAt in the update loop of your camera script.
you might also wans to check out the camera scripts that are available in the regular standard assets
How would I create a loop with lookAT() in the update some sample code would be greate.
Thanks
kcarriedo
well, you could use the lookAt code you’ve already got, wrap it in a function… Then call it from the main loop with a boolean
function Update()
{
if (isLooking) lookAt();
}
function lookAt()
{
// All your camera lookat code
}
Obviously, whatever triggers that lookat will also need to toggle the isLooking from false to true 
Here is what I’m working with. right now when I click on the object the camera moves to its location but then when I move it moves off it. What I’m trying to do is lock it all the time or until the object is destroyed. What am I doing wrong?
Thanks
kcarriedo
static var currentObject;
var target : Transform;
function Update() {
var hit : RaycastHit;
for (var evt : iPhoneTouch in iPhoneInput.touches) {
if (evt.phase == iPhoneTouchPhase.Began || evt.phase == iPhoneTouchPhase.Moved) {
var line = Camera.main.ScreenPointToRay (evt.position);
if (Physics.Raycast (line, hit, 500)) {
Debug.DrawLine (line.origin, hit.point, Color.red);
currentObject = hit.collider.name;
print(currentObject);
if(currentObject == "barrel")
{
LookAt();
}
}
}
}
}
function LookAt()
{
transform.LookAt(target);
}