Javascript scripting examples



  • Here you can find some javascript scripting examples:

    1. The model will be anchored to the camera and will look directly to at it. adjust the variable ‘distanceFromCamera’ in order to control how far it will be from the camera.
    var distanceFromCamera = 2.0;
    
    function update(deltaTime)
    {
        object.transform.lookAt(Camera.position);
        object.transform.position = Vector3.add(Camera.position, Vector3.multiply(Camera.forward, distanceFromCamera));
    }
    
    1. Rotating an object when pressing on a button. Use this script on the object that you want to rotate and has a button component on it.
    var buttonIsPressed = false;
    
    object.button.onPressed = function () {
        buttonIsPressed = !buttonIsPressed;
    }
    
    function update(deltaTime) {
        if (buttonIsPressed) {
            object.transform.rotate(30 * deltaTime, Vector3.up);
    }
    }
    

    'buttonIsPressed' variable will change every time you press on the button.
    If the variable is true - it will spin the object.


Log in to reply