Random Object Rotation Script
Hi all!
Sometimes you need to make a custom solution. So, here is one of them.
I'm just starting to code and don't pretend to do anything but maybe in the future it will be useful to someone
This code allows you to rotate an object at random coordinates that you can choose between two numbers. Also, choose any axes. You can also set the timing of the position change.
Huge thanks to Josh Beckwith and modelsbymike3d for point me in right direction!
// @input SceneObject obj
// @input float From
// @input float To
// @input int delay = 1
// @input int every = 1
// @input bool randomX
// @input bool randomY
// @input bool randomZ
var from = script.From;
var to = script.To;
var delay = script.delay;
var every = script.every;
function GetRandomFloat(min, max) {
return Math.random() * ((max) - min) + min;
}
var delayedEvent = script.createEvent("DelayedCallbackEvent");
delayedEvent.bind(function()
{
var randomNum = GetRandomFloat(from, to);
delayedEvent.reset(every);
print('delay is resetting');
var rot = script.obj.getTransform().getWorldRotation().toEulerAngles();
var x = 0.0;
var y = 0.0;
var z = 0.0;
if(script.randomX) {
x = randomNum;
}
if(script.randomY) {
y = randomNum;
}
if(script.randomZ) {
z = randomNum;
}
var newRotation = quat.fromEulerAngles(x,y,z);
script.obj.getTransform().setWorldRotation(newRotation);
});
delayedEvent.reset(delay);
print("delay has started");
oow, cool, thanks for sharing!
kme my pleasure
Hey Jorik Rosa
Thanks for this script! Do you know what I can add to make it stop rotating on tap? I'm very new to scripting.
Thanks for this script! Do you know what I can add to make it stop rotating on new tap? I'm very new to scripting.