Skip to content
Snippets Groups Projects
Commit 3d371cc2 authored by Dietrich Gerstenberger's avatar Dietrich Gerstenberger
Browse files

1st script

parent 0fad7a6b
No related branches found
No related tags found
No related merge requests found
File added
// Ruft den Pfad des Skripts relativ zum Basispfad des Objekts ab
var scriptPath = Script.resolvePath(".");
// Extrahiert die ID des Objekts aus dem Pfad
var lightID = scriptPath.slice(1, scriptPath.indexOf("/", 1));
var lightID = "{d4e37d71-b6e4-425d-ab2b-673f09fb1339}"
var minX = -110;
var maxX = -70;
var yDeg = 0;
var minZ = -20;
var maxZ = 20;
// Aktualisiert die Rotation der Lichtquelle
function setRotation() {
//Zufälliger Winkel
const rangeX = maxX - minX;
const randomNumberInRangeX = Math.random() * rangeX;
const randomNumberBetweenX = randomNumberInRangeX + minX;
const rangeZ = maxZ - minZ;
const randomNumberInRangeZ = Math.random() * rangeZ;
const randomNumberBetweenZ = randomNumberInRangeZ + minZ;
// Konvertieren Grad in Radiant
const xRad = (randomNumberBetweenX / 180) * Math.PI;
const yRad = (yDeg / 180) * Math.PI;
const zRad = (randomNumberBetweenZ / 180) * Math.PI;
// Die Entity mit der gegebenen ID finden
const entity = Entities.getEntityProperties(lightID);
// Die aktuelle Rotation der Entity abrufen
const currentRotation = entity.rotation;
// Die neue Rotation berechnen
const newRotation = Quat.fromPitchYawRollRadians(xRad, yRad, zRad);
// Die neue Rotation auf die Entity setzen
Entities.editEntity(lightID, { rotation: newRotation });
}
// Ruft updatePosition() in regelmäßigen Abständen auf
Script.setInterval(setRotation, 500);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment