Skip to content

Instantly share code, notes, and snippets.

@thelucre
Created March 9, 2019 00:19
Show Gist options
  • Save thelucre/66be040506007c021e161de2eea0f992 to your computer and use it in GitHub Desktop.
Save thelucre/66be040506007c021e161de2eea0f992 to your computer and use it in GitHub Desktop.
AutoRotate script for Snapchat Lens Studio
// -----JS CODE-----
//@input vec3 Rotation
//@input float Speed
// Equivalent to GameObject
var object = script.getSceneObject();
// Just like Unity Transform!
var transform = script.getTransform();
function onUpdate(ev) {
var transform = script.getTransform();
var rotation = transform.getLocalRotation();
var amt = script.Rotation.uniformScale(getDeltaTime() * script.Speed);
var rotateY = quat.angleAxis(amt.x, vec3.up());
var rotateX = quat.angleAxis(amt.y, vec3.left());
var rotateZ = quat.angleAxis(amt.z, vec3.forward());
rotation = rotation
.multiply(rotateY)
.multiply(rotateX)
.multiply(rotateZ);
transform.setLocalRotation(rotation);
}
var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(onUpdate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment