Difference between revisions of "Setting Local Rotation"
Jump to navigation
Jump to search
imported>Fg109 m (forgot to add to solutions category) |
imported>Fg109 m |
||
Line 1: | Line 1: | ||
[[Category:Solutions]] | [[Category:Solutions]] | ||
The [[SetAngle_-_ObjectReference|SetAngle]] function rotates an object according to the global axes, not the local axes of an object. This means that if you were to script the movement of a ship, for example, you would be unable to account for pitch and roll (rotation about the x and y axes). | The [[SetAngle_-_ObjectReference|SetAngle]] function rotates an object according to the global axes, not the local axes of an object. This means that if you were to script the movement of a ship, for example, you would be unable to account for pitch and roll (rotation about the x and y axes). | ||
Revision as of 11:21, 3 April 2012
The SetAngle function rotates an object according to the global axes, not the local axes of an object. This means that if you were to script the movement of a ship, for example, you would be unable to account for pitch and roll (rotation about the x and y axes).
To rotate the object about its local axes, use this function:
Function SetLocalAngle(Float LocalX, Float LocalY, Float LocalZ)
float AngleX = LocalX * Math.Cos(LocalZ) + LocalY * Math.Sin(LocalZ)
float AngleY = LocalY * Math.Cos(LocalZ) - LocalX * Math.Sin(LocalZ)
SetAngle(AngleX, AngleY, LocalZ)
EndFunction
So if you wanted to have the ship roll 15 degrees over to its left side, while experiencing some pitch causing it to tilt up 10 degrees, on a heading of 135 degrees, you would use:
SetLocalAngle(-10, 15, 135)
The function is meant to be put on a scripted object, and will move only that object when called. You can easily make it a global function by changing it to this:
Function SetLocalAngle(ObjectReference MyObject, Float LocalX, Float LocalY, Float LocalZ) Global
float AngleX = LocalX * Math.Cos(LocalZ) + LocalY * Math.Sin(LocalZ)
float AngleY = LocalY * Math.Cos(LocalZ) - LocalX * Math.Sin(LocalZ)
MyObject.SetAngle(AngleX, AngleY, LocalZ)
EndFunction
Obviously, the 'MyObject' parameter is for the object you want to rotate.