vr adventure game in gallery

37 views
Skip to first unread message

박정민

unread,
Sep 13, 2017, 10:56:23 PM9/13/17
to CoSpaces Scripting
In the gallery, when the user falls outside in the VR adventure game, it will return to its original position, and then the camera starts to fall from the top. How can I code it?

Benjamin Singh

unread,
Sep 14, 2017, 3:24:26 AM9/14/17
to cospaces-...@googlegroups.com
Hi,

here is the exact JavaScript code used in the game. I added some comments as well.

// start position of the player
var startPos = {x: 0, y: -30, z: 15};

// get camera object which represents the player
var cam = Scene.getCamera();
var camPos;

// for every frame...
Scene.scheduleRepeating(function() {

   
// ...get the position of the camera
    camPos
= cam.getPosition();

   
// if the z-coordinate (height) is less than 2...
   
if(camPos.z < 2) {

       
// ...set the camera position to the start position
        cam
.setPosition(startPos.x, startPos.y, startPos.z);
   
}
}, 0);

The idea is:

1. Determine a start position of the player which consists of the three space coordinates x, y and z. This depends on your level.
2. For every frame -> check if the players z-position (the camera object) is less then lowest platform in your game.
 2.1. If this is the case, the player fell and you need to reset the position of the player.

Benjamin

Reply all
Reply to author
Forward
0 new messages