- Home /
How can i set the mesh front?
I have a game object that is created and placed through script and it gets a component with a function that should rotate it to face a target, and I'm using this piece of code:
Vector3 dir = alvo.position - eu.position;
Vector3 forward = eu.forward;
forward.y *= -1;
Vector3 rotation = Vector3.RotateTowards(forward, dir, 1, 0.0f);
transform.rotation = Quaternion.LookRotation(rotation);
where alvo = target (in portuguese) and eu = me (in portuguese) = gameObject and it works the axis z points to the target, but it makes the mesh to be turned 90 degrees in the axis y =( is there a way to tell unity that the canon is the front of the mesh, not the side of it?
Comment
Best Answer
Answer by clunk47 · Sep 27, 2013 at 02:08 AM
Try creating an empty gameObject with the desired rotation, make your cannon a child of it, place the script on the parent instead of the cannon mesh itself.
Your answer
![](https://koobas.hobune.stream/wayback/20220613114858im_/https://answers.unity.com/themes/thub/images/avi.jpg)