Search Unity

Rolling a cuboid - 2x1 box.

Discussion in 'Editor & General Support' started by daveMennenoh, Oct 30, 2020.

  1. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    107
    I watched a nice video tutorial about rolling a cube in Unity, which helped me a lot:

    But I am rolling a cuboid instead - and it's a bit more work for sure. I have the rolling worked out, however my issue is one of error accumulation. I am rotating 90º in .5 sec and it's never exactly 90º - so at the end of the rotation I need to set it to what the rotation should be...
    In the video he uses:
    Code (CSharp):
    1. Quaternion rotation = transform.rotation;
    2.         Quaternion endRotation = rotation * Quaternion.Euler(rollAxis * targetRollAngle);
    And then sets the transform.rotation to the endRotation after the roll is complete.
    This works fine if I just roll the short way, but if I stand it up on end and then roll it back down it will sink into the floor like so:

    I feel like it's the rollAxis in that calculation that is the problem. I calculate the roll point and use that in transform.RotateAround so that the rollAxis is at the rollPoint. But it's not being used here...
    thoughts?
     
  2. daveMennenoh

    daveMennenoh

    Joined:
    May 14, 2020
    Posts:
    107
    Realized I was getting the rotation from the manager object the script is on - and not the cube object I needed. Have it working much better now.
    Code (CSharp):
    1. Quaternion rotation = theCube.transform.rotation;