Waypoint Arrow not pointing at tagged object ?

Hi ,strange problem here as usual lol ,I am using a simple piece of code which is attached to a cone mesh which is a child of the main camera and I want it to point at my tagged waypoints in turn ,so I start simple and use waypoint 1 (tagged as “1”) and the arrow rotates but actually points at the center of my terrain and not the tagged waypoint ?
(I have checked and the terrain is not tagged at all) ? heres the JS (pragma strict) .
Any clue ?

#pragma strict
function Update () {
     
    var object = GameObject.FindGameObjectWithTag("1");
    var target = object.transform;
    transform.LookAt(target , Vector3(0,0,1));
    transform.rotation = transform.rotation * Quaternion.Euler(90,0,0);

}

lol fixed ,I had a DUH moment after I posted ,the Original code was wrong the line

transform.LookAt(target , Vector3(0,0,1));

should be

transform.LookAt(target);

Hope this helps people with arrow pointer problems lol :slight_smile:

FindObjectOfType() is very slow and should not be done every frame. Typically you would give the game object with the script attached a name know name and use GameObject.Find() to get the object in start (or drag and drop into a public variable). I also don’t see where ckp is declared or set in this code, so I cannot check how that is being used. And you execute code even if object has not been initialized. Here is your code with a couple of mods:

#pragma strict

var other : CheckPoint01;

function Start () {
 	other = GameObject.Find("Other_Name").GetComponent(CheckPoint01);
}

function Update () {
    var object : GameObject = null;
    
    if (other.ckp==1) 
    	object = GameObject.FindGameObjectWithTag("1");
    if (other.ckp==2) 
    	object = GameObject.FindGameObjectWithTag("2");
 	
 	if (object != null) {
    	var target = object.transform;
 
		transform.LookAt(target);
 		transform.rotation = transform.rotation * Quaternion.Euler(90,0,0);
 		}
}

I assume the transform.rotation is because the natural rotation of the arrow is not towards positive ‘z’?