Random colors
// Define all possible hexadecimal characters.
hexChars = "0123456789ABCDEF"
// Start the color string with a hash.
color = "#"
for i in range(1, 6)
randIndex = floor(rnd * 16)
color = color + hexChars[randIndex]
end for
setLightObject "Spot1", color, rnd, "hard", rnd
Move objects by random in an area
targetObject = "eagle"
// Define the boundaries for the movement area.
xMin = -50
xMax = 50
y = 12
zMin = -100
zMax = 100
// Set the initial position of the object to a random point within the area.
x = xMin + rnd * (xMax - xMin)
z = zMin + rnd * (zMax - zMin)
moveObject targetObject, x, y, z
x2 = xMin + rnd * (xMax - xMin)
z2 = zMin + rnd * (zMax - zMin)
// Calculate the angle to face the new destination.
// atan returns radians, so we convert to degrees.
angle = atan(z2 - z, x2 - x) * 180 / pi
rotateObject targetObject, 0, angle, 0
// Animate the movement towards the destination in 100 small steps.
for j in range(1, 100)
// Interpolate the position for a smooth transition.
x = x + (x2 - x) / 100
z = z + (z2 - z) / 100
moveObject targetObject, x, y, z
wait 0.01
end for
end while
Move 26 Cubes to a Rubik Cube
// === Configuration ===
// Defines the visual properties and layout of the cube formation.
cubeSize = 0.57
spacing = 0.1
baseObjectName = "Cube"
center = {"x": 0, "y": 0, "z": 0}
animationDelay = 0.05 // A short delay for a staggered creation effect.
// === Main Logic ===
// This script arranges 26 cubes in a 3x3x3 grid, leaving the center empty.
index = 1
// Loop through a 3x3x3 grid using coordinates from -1 to 1 on each axis.
for x in range(-1, 1)
for y in range(-1, 1)
for z in range(-1, 1)
// Skip the very center of the grid (0, 0, 0) to leave it empty.
if x == 0 and y == 0 and z == 0 then continue
// Calculate the final position for the current cube.
posX = center.x + x * (cubeSize + spacing)
posY = center.y + y * (cubeSize + spacing)
posZ = center.z + z * (cubeSize + spacing)
// Construct the unique object name (e.g., "Cube1", "Cube2", etc.).
objectName = baseObjectName + index
// Position and scale the cube object.
moveObject objectName, posX, posY, posZ
scaleObject objectName, cubeSize, cubeSize, cubeSize
// Increment the index for the next cube.
index = index + 1
// Wait briefly before creating the next cube.
wait animationDelay
end for
end forend for
Horse run clockwise
// Configuration
targetObject = "horse_run"
animationIndex = "1"
animationSpeed = 2
center = {"x": 0, "z": 0}
radius = 90
height = 0.2
angularSpeed = -pi / 32
timeStep = 0.1
updateInterval = 0.01
totalSteps = 200000
// Initialization
aniObject targetObject, animationIndex, "oneshot", animationSpeed
// Main loop
timeCounter = 0
for i in range(1, totalSteps)
// Calculate angle
currentAngle = angularSpeed * timeCounter
// Calculate position
posX = center.x + radius * cos(currentAngle)
posZ = center.z + radius * sin(currentAngle)
moveObject targetObject, posX, height, posZ
// Calculate rotation
yAngle = -currentAngle * 180 / pi
rotateObject targetObject, 0, yAngle, 0
// Increment counter
timeCounter = timeCounter + timeStep
// Short pause
wait updateInterval
end for
Amplitude
// === Configuration ===
targetObject = "Cylinder1"
basePosition = {"x": 2, "y": 2, "z": 2}
// Oscillation properties.
amplitude = 0.001
frequency = 4
updateInterval = 0.01
while true
t = time
newX = basePosition.x + amplitude * cos(frequency * t)
newY = basePosition.y + amplitude * sin(frequency * t)
moveObject targetObject, newX, newY, basePosition.z
wait updateInterval
end while
Place objects by random in an area
targetObject = “myObject”
area = {“xMin”: -10, “xMax”: 10, “y”: 11, “zMin”: -20, “zMax”: 20}
minScale = 0.1
maxScale = 1.1
duration = 1200
updateInterval = 0.08
endTime = time + duration
while time < endTime
x = area.xMin + rnd * (area.xMax – area.xMin)
z = area.zMin + rnd * (area.zMax – area.zMin)
moveObject targetObject, x, area.y, z
scale = minScale + rnd * (maxScale – minScale)
scaleObject targetObject, scale, scale, scale
wait updateInterval
end while
Change Texture by random
// Configuration
targetObject = "Image1"
imageUrls = [
"https://metaverse.xrxplorer.com/my-content/images/1.png",
"https://metaverse.xrxplorer.com/my-content/images/2.png",
"https://metaverse.xrxplorer.com/my-content/images/3.png"
]
changeInterval = 2
// Main loop
while true
randomIndex = floor(rnd * imageUrls.len)
randomUrl = imageUrls[randomIndex]
networkCommand targetObject, "changeTexture", randomUrl
wait changeInterval
end while
Create and show a random Number in a Message Box
// Configuration
title = "The Random Number"
targetNumber = 42
// Generate a random number from 0 to 50.
randomNumber = floor(rnd * 51)
message = ""
// Check the result and build the appropriate message.
if randomNumber == targetNumber then
message = "The random number is " + randomNumber + ". You are lucky!"
else if randomNumber <= 25 then
difference = targetNumber - randomNumber
message = "The random number was " + randomNumber + "." +
"Just for fun: " + randomNumber + " + " + difference + " equals " + targetNumber + "."
else
message = "The random number was " + randomNumber + "." +
"That's close. The next time, you'll be right."
end if
// Display the final message.
messageBox title, message
Message Box with typewriter effect
tips = {
1: “This message disappears when you click somewhere. Type this command to use this message box: => messageBox, sTitle, sMessage”,
2: “You can create dynamic effects by combining loops, random numbers, and the wait() command.”,
3: “My third random message”}
tipNumber = floor(rnd * tips.len) + 1
selectedTip = tips[tipNumber]
title = “Quicktip Nr°” + tipNumber
for i in range(1, selectedTip.len)
messageBox title, selectedTip[:i]
wait rnd / 20
end for
messageBox title, selectedTip