# Quaternion calculations

Hi there!

``````a=Vector3(0,5,10);
b=Vector3(2,3,6);
``````

The two vectors can be calculated, substracted, etc, easily.

But how can the same be achieved with Quaternions, I mean the short notation instead of referring to .x, .y, .z, .w with four seperate lines?

Secondly check out:
http://www.stickystudios.com/etc/har.html

You can stand on the moving platform, but unfortunately rotation goes flaky.
Besides that problem, the problem is that the character is not standing on the same position as the platform when you stand on the corner.

The most ideal situation would be to make the character a child of the platform as soon there’s a touch down. But this will cause problems, I’d like to keep the character in the same hierarchy.

Does anyone have an idea how the character on the edge of a platform, will keep on the edge, when the platform is rotating?

Yoggy did a great example of this…

http://forum.otee.dk/viewtopic.php?t=1358

thanks! I contacted Yoggy because the download links are not there, but this will get me started. It seems Yoggy choose to not use the char.controller but physics.

Just so you know, you can’t subtract rotation quaternions in a meaningful way. In fact, anything which involves editing the x, y, z and w components of a quaternion is likely to result in messed up rotations.

If you need to get from one rotation to another, you need to interpolate between the two quaternions. This can be done with the Quaternion.Lerp/Slerp() class methods. For example:

``````// JavaScript (probably), written in a verbose way for clarity:

startRotation = transform.rotation;
destinationRotation = Quaternion.EulerAngles(x, y, z);        // Or anything else you want

// The factor specifies how far you want to go from one rotation to another.  0.0 gives you startRotation,
// 1.0 gives you destinationRotation and 0.5 gives you something halfway between the two.

factor = 0.1f;

newRotation = Quaternion.Slerp(startRotation, destinationRotation, factor);

// Then you might want to punch it back into your transform:

transform.rotation = newRotation;
``````

In this case it is probably easiest to just store the position relative to the platform.
Next fame you just calculate where the local space position is in world space now. Then you subtract from the current position and you have the movement of the platform at that particular point on the platform.

``````var oldLocalSpacePosition : Vector3;

// Store the local space position
oldLocalSpacePosition = platform.InverseTransformPoint(transform.position);

// Calculate how much the platform has moved (This includes rotation)
var delta = platform.TransformPoint(oldLocalSpacePosition) - oldLocalSpacePosition;
``````

wow. Thanks guys.
I will need to study those examples a bit, it’s Monday and my brains need to get a kickstart from the weekend!

Clever solutions.