Auto Movement in VR


#1

Hi, how can it be accomplished? Or any other/built in way to move in look direction?


#2

Hi,

you can do so using some JavaScript.

For example you can get the position and the direction of the camera, both can be represented as vectors. Then you simply add the direction vector to the position vector (some scaling needed) to get your new position. Use this code snippet to test it, just replace the camera ID and set speed to whatever you like.

const cam = Scene.getItem('7XESg2LNFF'); // replace with your camera ID
const speed = 2; // higher => faster

// for every frame...
Scene.scheduleRepeating(() => {
    let pos = cam.getPosition(); // get cam position
    let dir = cam.getDirection(); // and cam direction
    
    // add components (I left out z for simplicity)
    let newPos = {
        x: pos.x + dir.x * speed * 0.01, // some scaling
        y: pos.y + dir.y * speed * 0.01
    };

    cam.setPosition(newPos.x, newPos.y, pos.z); // set new cam position
}, 0);

With that you should automatically move towards the direction you’re looking at.