- Home /
align y axis of a gameobject to z axis of another gameobject ???
player in my game has its z axis facing in direction it is moving, so y is its vertical axis
i have another gameobject sitting on the ground, which has z axis as vertical axis
i want to instantiate this gameobject from player script, but obviously z axis of instantiated gameobject is facing where player is facing and not above
how should i do this ?
also
when i shoot bullets, i want to instantiate bullet hole sprite at point of contact, i am able to get an axis normal to that surface, how do i align instantiated sprite's z axis to that normal axis
Answer by theterrificjd · Jul 26, 2020 at 11:59 AM
You could create an empty gameobject as a parent of the child object whose rotation needs to be fixed, and simply change the local euler angles of the child object so that instantiating it to Quaternion.Identity (the default look rotation) is already correct.
Or you could change the rotation in script to either manually rotate by the desired offset, or use a slightly heavier function like
transform.rotation = Quaternion.LookRotation(Vector3.up, Vector3.right);
for aligning bullet holes with surface the bullet struck
ContactPoint coco = collision.contacts[0];
Quaternion normalAngle = Quaternion.Euler(coco.normal);
it gives output like (1,0,0) or (0,-1,0)
1 or -1 represents axis it is facing. in this case it is x and negative y
now i want to instantiate a gameobject whose z axis is equal to normalAngle
from the above, (z,0,0) or (0,-z,0)
how should i do that?
Your answer
![](https://koobas.hobune.stream/wayback/20220613004118im_/https://answers.unity.com/themes/thub/images/avi.jpg)