4
\$\begingroup\$

I spent some time in Unity yesterday trying to fire a sphere from a horizontal cylinder (like a ball from a cannon). I was using Vector3.forward, but the sphere kept coming out the top of the cylinder rather than the front. Someone suggested using Vector3.up instead, and sure enough it worked!

The cylinder is vertical by default. So, it appears that when I rotated the cylinder by 90 degrees to lay it flat, the local axes remained the same. The relative front of the cylinder remained at the same point, so when I fired the sphere it shot out the new "top", not what looked to me like the "front". If I had happened to be facing the other way, I would have had to fire at Vector3.down instead.

How can I reorient/reset the axes of an object so that they match my expectations? (And if I can't, how can I tell by looking which way an object is oriented?)

\$\endgroup\$

3 Answers 3

6
\$\begingroup\$

Click on the object in the scene, and look at the Rotation values in the Inspector. This will tell you which way the object is oriented in absolute terms.

If the orientation does not match your expected axis (for example, 90 degrees off, or using an unintuitive axis for a given direction), you cannot change the axis of the object itself. Instead, you can use a "parent transform" as follows:

Create an empty GameObject as a parent of your object, and align its transform with your model's expected axis. Now use the parent transform to reference and manipulate the child object.

\$\endgroup\$
0
0
\$\begingroup\$

Try using transform.up and transform.right instead of Vector3. Vector3 takes the world coordinates and transform.up takes into account the transform's orientation.

\$\endgroup\$
1
  • \$\begingroup\$ hmmm, I think I misremembered and I actually was using transform.forward (and that didn't work) - I'll have to check my code and comment further... thanks for the tip \$\endgroup\$
    – lofidevops
    Commented Apr 10, 2014 at 11:15
0
\$\begingroup\$

But if your model don't be modeled to get the axis z to front in the modeller program you can't arrange this in unity

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .