Jump to content

Camera Jump


bombe93
 Share

Recommended Posts

this is my version on jump camp.

Help for to get better  jump

 

<html>
<style>
    htmlbody {
        overflowhidden;
        width   : 100%;
        height  : 100%;
        margin  : 0;
        padding : 0;
    }
 
    #renderCanvas {
        width   : 100%;
        height  : 100%;
        touch-actionnone;
    }
</style>
<head>
    <meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
    <title>Babylon - Getting Started</title>
   <!-- Link to the last version of BabylonJS -->
    <script src="https://preview.babylonjs.com/babylon.js"></script>
    <!-- Link to the last version of BabylonJS loaders to enable loading filetypes such as .gltf -->
    <script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
    <!-- Link to pep.js to ensure pointer events work consistently in all browsers -->
    <script src="https://code.jquery.com/pep/0.4.1/pep.js"></script>
</head>
<body>
    <canvas id="renderCanvas"></canvas>
</body>
<script>
    var obj = {
        cavas: null,
        engine: null,
        scene: null,
        camera: null,
        init: ()=>{
            let { addScene } = obj;
            obj.canvas = document.getElementById('renderCanvas');
            obj.engine = new BABYLON.Engine(obj.canvas, true);
            obj.scene = new BABYLON.Scene(obj.engine);
            addScene();
        },
        addScene: ()=>{
            let { scene, canvas } = obj;
            scene.gravity = new BABYLON.Vector3(0-0.90);
            scene.collisionsEnabled = true;
 
            obj.camera = new BABYLON.FreeCamera("FreeCamera"new BABYLON.Vector3(05-20), scene);
            let { camera } = obj;
            camera.attachControl(canvas, true);
            camera.checkCollisions = true;
            camera.applyGravity = true;
 
            var light = new BABYLON.HemisphericLight('light1'new BABYLON.Vector3(0,1,0), scene);
 
            var sphere = BABYLON.Mesh.CreateSphere('sphere1'52, scene);
            sphere.wireframe = true;
            sphere.position.y = 1;
            
            var myBox = BABYLON.MeshBuilder.CreateBox("myBox", {height: 3, width: 2, depth: 0.5}, scene);
            myBox.position.y = 1.5;
            myBox.position.x = 3;
            
            var ground = BABYLON.Mesh.CreateGround('ground1'1001002, scene);
            // return the created scene
            /*colicipon contra la camara (persona)*/
            ground.checkCollisions = true;
            myBox.checkCollisions = true;
        },
        onKeyUpfunction (event) {
            switch (event.keyCode) {
                case 32:
                    let { camera } = obj;
                    camera.position.y += 6;
                break;
            }
        }
    };
    window.addEventListener('DOMContentLoaded'function(){
        obj.init();
        // run the render loop
        obj.engine.runRenderLoop(function(){
            obj.scene.render();
        });
    });
 
    // the canvas/window resize event handler
    window.addEventListener('resize'function(){
        obj.engine.resize();
    });
    window.addEventListener("keyup", obj.onKeyUp, false);
</script>
</html>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...