- Home /
Make object face direction only on one axis
So I have an object that can be placed on another object, the problem is that when the object is placed on another surface with a different rotation the "up" rotation of the object changes.
Its easier to explain in pictures:
Lets say the part of the tire that says "Big Wheel" is the top of the object
When that object is moved to the other side of the engine (big white object) the wheel rotates so that "BigWheel" is now facing the side:
I do not want the wheel to rotate like that, I want it to always be facing the same way on one axis.
Please note that in this part of my game the player is creating a vehicle and the wheels need to be facing the ground so that the WheelColliders work when the player runs the simulation. Also the wheel consists of two objects (the wheel and the "axel" which the wheel is parented to).
What sort of code are you using to orient them?
$$anonymous$$y 1st try would be to assume you have empties as placement mountPoints, and use tire.rotation = placeTarget[i].rotation;
.
But that would make it work the way you want, so you must have some other set-up, where the obvious way won't work.
They are just parented to the axel, with no other code to change their direction.
It seems like the evidence says there is code, somewhere, to change the direction.
Just rechilding: wheel.parent=axel2;
doesn't change position or rotation (but might change it later, as the parent moves/spins.)
Answer by ScroodgeM · Jul 23, 2012 at 06:46 PM
don't use euler angles (rotation XYZ in inspector) to store "up" rotation. euler angles is just a representation of Quaternion (rotation is stored in this format). not unique. so two different rotations in euler angles can be the same.
so first create a default rotation (where wheel is UP (strange sounds)) and then use transform.RotateAround(...) method to rotate around Y axis. so you can be sure wheel always be UP
for example (imagine or try that) when you rotate an object in euler angles by 90 or 270 degrees around X axis, your Y and Z rotations are rotates object around the same axis...