Physics Basic Shape: GoToPosition
Move the shape until it is at the specified position.
Only one movement can be performed at a time. If this function is called before a previous movement has completed, the first movement will stop where it is, and the new movement will start from that position.
All positions, speeds, and units are in project units. That is to say, the distance, speed, and acceleration is meters, meters/second, and meters/second^2 for metric projects, and feet, feet/second, and feet/second^2 for imperial projects.
Function
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, xAcc, xDec, yAcc, yDec, zAcc, zDec);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction, xAcc, xDec, yAcc, yDec, zAcc, zDec);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction, CallbackInterval);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction, CallbackInterval, xAcc, xDec, yAcc, yDec, zAcc, zDec);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction, intOffsetArray);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction, intOffsetArray, xAcc, xDec, yAcc, yDec, zAcc, zDec);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, xAcc, xDec, yAcc, yDec, zAcc, zDec, initX, initY, initZ);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction, xAcc, xDec, yAcc, yDec, zAcc, zDec, initX, initY, initZ);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction, CallbackInterval, xAcc, xDec, yAcc, yDec, zAcc, zDec, initX, initY, initZ);
void GoToPosition(x, y, z, xSpeed, ySpeed, zSpeed, CallbackFunction, intOffsetArray, xAcc, xDec, yAcc, yDec, zAcc, zDec, initX, initY, initZ);
Parameters
Name | Type | Description |
---|---|---|
x | Number | The X coordinate of the target position |
y | Number | The Y coordinate of the target position |
z | Number | The Z coordinate of the target position |
xSpeed | Number | The speed along the X axis |
ySpeed | Number | The speed along the Y axis |
zSpeed | Number | The speed along the Z axis |
CallbackFunction | function(sender, x, y, z) | Callback function will be called with the shape and the coordinates. |
CallbackInterval | Number | Interval in milliseconds when callback function is called over the course of the movement. |
intOffsetArray | Array | Array of integer values in milliseconds. The callback function is called when the movement is that many milliseconds before completion. |
xAcc | Number | Acceleration of X axis |
xDec | Number | Deceleration of X axis |
yAcc | Number | Acceleration of Y axis |
yDec | Number | Deceleration of Y axis |
zAcc | Number | Acceleration of Z axis |
zDec | Number | Deceleration of Z axis |
initX | Number | The initial speed of the X axis. The object will accelerate/decelerate towards xSpeed. |
initY | Number | The initial speed of the Y axis. The object will accelerate/decelerate towards ySpeed. |
initZ | Number | The initial speed of the Z axis. The object will accelerate/decelerate towards zSpeed. |
Example
function OnSimulationStart()
{
let shape1 = GetComponentByNameAndType("PhysicsBasicShape1", "Physics Basic Shape");
// Start moving 'shape1' towards position '(20, 30, 40)'.
// The X axis will move at 5 units/second, the Y at 3, and the Z at 2.
// When the movement is complete, the 'OnMovementComplete' function will be called.
shape1.GoToPosition(20, 30, 40, 5, 3, 2, OnMovementComplete);
let shape2 = GetComponentByNameAndType("PhysicsBasicShape2", "Physics Basic Shape");
let pos = shape2.GetPosition();
shape2.GoToPosition(
pos[0] + 100, pos[1], pos[2], // Move 100 units along the X axis.
10, 0, 0, // Move at a top speed of 10 units/second.
OnMovementComplete, // Call 'OnMovementComplete' at movement's end.
0.25, 0.5, // Accelerate X at 0.25, decelerate X at -0.5.
0, 0, 0, 0, // All other axes have 0 acceleration and deceleration.
3, 0, 0 // Start the movement at 3 units/second.
);
}
// Params:
// sender: The Physics Basic Shape that caused this callback to be called.
// x: The X position of the object when the callback was called.
// y: The Y position of the object when the callback was called.
// z: The Z position of the object when the callback was called.
// speedX: The X axis speed of the object when the callback was called.
// speedY: The Y axis speed of the object when the callback was called.
// speedZ: The Z axis speed of the object when the callback was called.
function OnMovementComplete(sender, x, y, z, speedX, speedY, speedZ)
{
LogDebug(`${sender.Name} = ${x} ${y} ${z} speed ${speedX} ${speedY} ${speedZ}`);
}