questions about quaternions and rotating objects

i came to the term “quaternion” when i was trying to solve a rotating problem with a cube puzzle i’ve been working on and i also found out about something called gimble lock and from my understanding both terms seem to be the fix for my problem.

the cube will be rotating with a keyboard input
its going to be rotated on 2 dimensions (X(roll),Y(pitch))
each keyboard input is going to rotate the cube on a single dimension for example Q is going to rotate on X and E for Y.

now the questions
1- my knowledge on quaternions is very basic so when should i use quaternions in game development in general?

2- do i need quaternion to make the cube rotate since its a puzzle and its not going to be a main game feature or a core feature.

3- does quat fix the gimble lock?

4- is there any alternatives to the quaternion?

I answered this here

You don’t need quaternions :slight_smile:


thank you so much this is exactly what i was looking for.

1 Like

i have another problem now your method works fine but the player is going to rotate the cube until he get the correct cube face facing up in order to solve it.
any ideas on how to do it? i was thinking of ways to make it work but i can’t figure it out especially when u now that there are multiple rotations in order to make the cube face facing the right direction.

1 Like

Not sure what you mean.

How to know when ‘face X’ is up?

ok u see this image the cube and the white platform

in order solve the puzzle you need to make this face of the cube (1) facing down (2) and put it on the platform (3) look at the image to understand it

the player will rotate on X and Y and will have the freedom to put the cube on which ever face he wants, my question is how do i know when he puts the cube on the platform with the correct face looking down?

now i do know how to make the cube rotate and move but what i dont know is how to tell if the correct cube face is the one that is facing the platform

i hope that clear it.

Was thinking you could use Dot Product the way each mesh is facing but that wouldn’t be 100%.

The most straightforward way imho would be:

  • put a socket on the center of the correct face that is supposed to be downward
  • put a thin flat volume on top of the platform
  • check if the cube surface socket is inside the volume on the platform

That would solve for both contact and the correct side.

1 Like

wow nice it worked, i parented a plane shape to the cube, moved it until it almost hit the correct face and used a box collision volume to trigger when this plane gets inside it.

thank you for your help sir.

1 Like

Yes, either collision ( like you did ), or vector math, so you know where the face is pointing.

just out of curiosity how should i do it with vector math?

and thanks for your help sir.

1 Like

Well you want to know when that face is pointing downward.

You could have an arrow component pointing outward from the face ( or an empty scene component ). When the dot product of that arrow and the actor down vector is ( approx ) 1, it’s facing downwards :slight_smile:

interesting idea.

1 Like