- Home /
I want to create a 3D compass (like in Bioshock) but it keeps rotating on all axes, including Y, even though it should only rotate on X and Z... (Code)
This is my code:
var update : boolean;
var currentTarget : GameObject;
var compassNeedle : GameObject;
var debug : boolean;
function Update () {
if(update){
var point: Vector3 = currentTarget.transform.position;
point.y = 0;
if(debug){
print(point);
}
compassNeedle.transform.LookAt(point);
}
}
When point is printed, it shows that point's Y coordinate is indeed 0, but for some reason the LookAt still points at the target with all axes.
I don't even know how this is possible, since LookAt uses the point variable which is at 0 on the Y axis.
Comment
Where is the compass at? If the compass.transform.y is zero then this code will work, otherwise ur going to have problems. If this is the case then this code might function the way u desire:
function Update ()
{
if (update)
{
var point: Vector3 = currentTarget.transform.position;
point.y = transform.position.y;
if (debug)
{
print(point);
}
compassNeedle.transform.LookAt(point);
}
}
Your answer
Follow this Question
Related Questions
Look At while locked in a position 1 Answer
Local child rotation and transform.LookAt 2 Answers
Making a specific axis look at an object 2 Answers
Issue with axis values when importing from 3ds max 1 Answer
Object facing the wrong way? 1 Answer