1
\$\begingroup\$

I have a cube that moves by rotating on its edge. I want my code to also work for cuboids. The following code is what I'm using to rotate my cube:

turnPoint = transform.position + new Vector3(0.5f * direction * x, -0.5f, 0.5f * direction * z); // Location of edge (resets every 90 degrees)
transform.RotateAround(turnPoint, axis, rotateSpeed * direction); // Turn around the edge

It works fine, however I want to get this to work when the cube is scaled to be a cuboid. I tried multiplying the new Vector3's x, y and z components by the objects respective x, y and z scale. This works, but only for the first rotation.

Is there a way this could work for all future rotations without using if/else for all 4 rotations?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.