local cube = Space.Host.ExecutingObject
local fromQuat = cube.LocalRotation
local toQuat = Quaternion.New(0.0, 0.707, 0.0, 0.707)
local speed = 0.1
-- The cube will rotate 90 degrees from current rotation by speed amount.
local moveCube = function()
cube.LocalRotation = fromQuat.Lerp(toQuat, Space.Time * speed);
end
cube.OnUpdate(moveCube)
Slerp
SQuaternion Slerp (SQuaternion b, float t)
Spherically interpolates between this and other quaternion, by factor t and returns the result
local cube = Space.Host.ExecutingObject;
local fromQuat = cube.LocalRotation;
local toQuat = Quaternion.New(0.0, 1.0, 0.0, 0.0);
local speed = 0.1;
-- The cube will rotate 180 degrees from current rotation by speed amount.
local moveCube = function()
cube.LocalRotation = fromQuat.Slerp(toQuat, Space.Time * speed)
end
cube.OnUpdate(moveCube)
local cube = Space.Host.ExecutingObject
local fromQuat = cube.LocalRotation
local target = Quaternion.New(0.0, 0.707, 0.0, 0.707)
local speed = 10.0
-- The cube will rotate 90 degrees from current rotation by step amount.
local moveCube = function()
local step = speed * Space.Time
cube.LocalRotation = fromQuat.RotateTowards(target, step)
end
cube.OnUpdate(moveCube)
Dot
float Dot (SQuaternion b)
Returns the dot product of this and another quaternion
Parameter
Type
Description
local quat = Quaternion.New(0.0, 0.707, 0.0, 0.707);
local quatOther = Quaternion.New(0.0, 0.0, 0.0, 1.0);
Space.Log(quat.Dot(quatOther));
-- prints 0.707000017166138
obj = Space.Host.ExecutingObject
originalRot = obj.LocalRotation
onStartMethod = function()
Space.Log(originalRot.x)
-- prints the X component of this object as a float
originalRot.x = 0.25
-- assigns 0.25 value to the X component
obj.LocalRotation = originalRot
-- sets the the new rotation
end
obj.OnStart(onStartMethod)
obj = Space.Host.ExecutingObject
originalRot = obj.LocalRotation
onStartMethod = function()
Space.Log(originalRot.y);
-- prints the Y component of this object as a float
originalRot.y = 0.25;
-- assigns 0.25 value to the Y component
obj.LocalRotation = originalRot;
-- sets the the new rotation
end
obj.OnStart(onStartMethod);
local obj = Space.Host.ExecutingObject;
local originalRot = obj.LocalRotation;
obj.SubscribeToEvents();
local onStartMethod = function()
Space.Log(originalRot.z);
-- prints the Z component of this object as a float
originalRot.z = 0.25;
-- assigns 0.25 value to the Z component
obj.LocalRotation = originalRot;
-- sets the the new rotation
end
obj.OnStart(onStartMethod);
local obj = Space.Host.ExecutingObject;
local originalRot = obj.LocalRotation;
obj.SubscribeToEvents();
local onStartMethod = function()
Space.Log(originalRot.w);
-- prints the W component of this object as a float
originalRot.w = 0.25;
-- assigns 0.25 value to the W component
obj.LocalRotation = originalRot;
-- sets the the new rotation
end
obj.OnStart(onStartMethod);