how to point the positive Y axis of an object to a direction
Hey. I'm trying to figure it out how to point the positive side of a game object to a direction. any help would be appreciated, this is the code that I'm currently using:
//naming the gameobject
GameObject zPathHolder = new GameObject(z > 0 ? "+Z Path Holder" : "-Z Path Holder");
//assigning the parent
zPathHolder.transform.SetParent(tempGO.transform);
//calculating the world positioni of the holder
Vector3 holderPosition = new Vector3(x * 10, y * 10, z * 10 + z * 5f);
//direction from center of the current block to the holder position
Vector3 dir = holderPosition - tempGO.transform.position;
//the rotation of the path holder
Quaternion holderRotation = Quaternion.LookRotation(dir, zPathHolder.transform.right);
//assigning the world position
zPathHolder.transform.position = holderPosition;
//assigning the rotation
zPathHolder.transform.rotation = holderRotation;
but it doesn't work as expected, how can I fix it?
What's going wrong with that code and which way are you trying to point the object's positive y ?
Quaternion.LookRotation(positiveZ, positiveY);
should work as such
This is what I'm trying to achieve:
the red dots are path holders and the blue dots are blocks (their position is used in the code by "tempGO")
this is what I get when I use the code that I posted:
Answer by NoseKills · Aug 28, 2017 at 06:09 AM
And you want the positive Y to point where the positive Z is pointing there?
Just switch the parameters around in your LookRotation
Quaternion holderRotation = Quaternion.LookRotation(zPathHolder.transform.right, dir);
The second parameter literally is where the positive Y will point as explained in the manual
In that case please accept the answer so this question becomes marked solved
Your answer
![](https://koobas.hobune.stream/wayback/20220612133454im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rotating an Object (To Face Another Object) Only on X and Y Axis 3 Answers
Cant stop object/ridgidbody from rotating 2 Answers
Auto level an object 0 Answers
After Rotating a Prefab, Transform.Position of children is inaccurate 1 Answer
Rotation and Gravity Relative to the Center of an Object 0 Answers