transform.right axis switching multiplying transform.forward with Quaternion

On internet i learned that we can multiply Quaternion with Vectors in order to get back that vector rotated but there is one thing that i cannot understand. This is the code:

transform.forward = Quaternion.Euler(New Vector3(90 * Time.deltaTime, 0,0) * transform.forward;

In this way the transform.forward of an object rotate around the global x axis but after a rotation of 90 degree the x axis of the trasform switch to the other side. Can anyone explain me this behaviour? I am not a math genius so please try to keep the explanation as simple as you can! Thanks a lot

This says “rotate this Transform such that the .forward vector ‘looks in’ the target direction, and assume my ‘up’ is world up (Vector3.up)”

But you are feeding in the original .forward of the Transform, so I guess it is sort of like a .Rotate() command?? I’d have to fiddle with it to be sure. It’s an odd approach for sure.

This code is not well formed, because it is similar to doing

number = multiplier * number;

What do you expect will happen with the number? Will it turn out linear?
No, assuming the number starts from 1 and multiplier is 2, the sequence will turn out to be exponential

1 2 4 8 16 32 64 128 256 512...

The problem is compounded by modularity because you’re working with angles, so imagine if 15 was a full cycle, you’d end up with the following sequence

1 2 4 8 1 1 1 1 1 1 ...

Which seems to be exactly what happens to you even though this was just a stupid analogy.

edit:
I made a mistake, in this example, because I’m avoiding 0 as the plague (and picked 15 instead of 16), it goes in a loop, however this is a contrived example

1 2 4 8 1 2 4 8 1 2 4 8 ...

/edit

What you really wanted is this

transform.forward = Quaternion.Euler(90f * Time.deltaTime, 0, 0) * Vector3.forward;

However I don’t encourage this way of doing things.

edit:
In fact, on a second thought, maybe I’m wrong with my explanation. As Kurt said, I’m not really sure what’s going on without trying it. This is not a good approach either way.

1 Like