• Content Count

  • Joined

  • Last visited

About Eisha

  • Rank

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hello @Wingnut thank you so much for a great explanation from your side. I appreciate it 🙂
  2. Hello @JohnK thanks for the response. Sure I will be pasting the code instead of sharing the zip file here. The middle brick sphere is just passing touching the red sphere. I don't understand how to make the ball pass fast in a smooth way without getting it touched with the red sphere. Please help me. So the code so far I have is here: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Babylon Template</title> <style> html, body { overflow: hidden; width: 100%; height: 100%; margin: 0; padding: 0; } #renderCanvas { width: 100%; height: 100%; touch-action: none; } </style> <script src="https://cdn.babylonjs.com/cannon.js"></script> <script src="https://cdn.babylonjs.com/babylon.js"></script> <script src="https://preview.babylonjs.com/loaders/babylonjs.loaders.min.js"></script> <script src="https://code.jquery.com/pep/0.4.3/pep.js"></script> </head> <body> <canvas id="renderCanvas" touch-action="none"></canvas> //touch-action="none" for best results from PEP <script> var canvas = document.getElementById("renderCanvas"); // Get the canvas element var engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine /******* Add the create scene function ******/ var createScene = function () { // Create the scene space var scene = new BABYLON.Scene(engine); // Add a camera to the scene and attach it to the canvas var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 10, new BABYLON.Vector3(0,0,0), scene); camera.attachControl(canvas, true); // Add lights to the scene var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene); var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene); // Add and manipulate meshes in the scene var sphere1 = BABYLON.MeshBuilder.CreateSphere("sphere1", {diameter:2}, scene); sphere1.position.y = 0.85; var sphere2 = BABYLON.MeshBuilder.CreateSphere("sphere2", {diameter:3}, scene); sphere2.position = new BABYLON.Vector3(0,0,0); sphere2.position.x=-3; sphere2.position.y = 0.55; var pinkMaterial = new BABYLON.StandardMaterial("pinkMaterial",scene); sphere2.material = pinkMaterial; pinkMaterial.diffuseColor = new BABYLON.Color3(1,.3,.6); var brickMaterial = new BABYLON.StandardMaterial("brickMaterial",scene); brickMaterial.diffuseTexture = new BABYLON.Texture("pexels-photo-761142.jpeg",scene); sphere1.material = brickMaterial; var ground = BABYLON.MeshBuilder.CreateGround("ground", {height: 100,width:100}, scene); ground.position = new BABYLON.Vector3(0,-2.5,-20); var grassMaterial = new BABYLON.StandardMaterial("pexels-photo-413195.jpeg",scene); ground.material = grassMaterial; grassMaterial.diffuseTexture = new BABYLON.Texture("pexels-photo-413195.jpeg",scene); grassMaterial.diffuseTexture.uScale = 10; grassMaterial.diffuseTexture.vScale = 4; scene.clearColor = new BABYLON.Color3(.8,.9,1); //Sphere 3 the blue sphere later on red var sphere3 = BABYLON.MeshBuilder.CreateSphere("sphere3", {diameter:2}, scene); sphere3.position = new BABYLON.Vector3(0,0,0); sphere3.position.x=3; sphere3.position.y = 0.55; var blueMaterial = new BABYLON.StandardMaterial("blueMaterial",scene); sphere3.material = blueMaterial; blueMaterial.diffuseColor = new BABYLON.Color3(.4,.3,4); var physicsPlugin = new BABYLON.CannonJSPlugin(); var gravityVector = new BABYLON.Vector3(0, -9.81, 0); scene.enablePhysics(gravityVector, physicsPlugin); sphere2.physicsImpostor = new BABYLON.PhysicsImpostor(sphere2, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1, restitution: 0.8 }, scene); ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 0.9 }, scene); sphere2.physicsImpostor.applyImpulse(new BABYLON.Vector3(1,2,0), sphere2.getAbsolutePosition()); sphere1.physicsImpostor = new BABYLON.PhysicsImpostor(sphere1, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 1, restitution: 0.9 }, scene); sphere1.physicsImpostor.applyImpulse(new BABYLON.Vector3(3,1,-0.55), sphere1.getAbsolutePosition()); var velocity = 0.005; var dir = -1; //for red ball to change direction var dir2 = -4; //for pink ball to change direction scene.registerAfterRender(function () { sphere3.position.y += velocity * dir; sphere2.position.x += velocity * dir2; if (sphere3.intersectsMesh(ground, false)) { sphere3.material.diffuseColor = new BABYLON.Color3(1, 0, 0); dir = 1.0; } if(sphere3.position.y > 3){ dir = -1; } if(sphere2.intersectsMesh(sphere1,false)){ //sphere2.material.emissiveColor = new BABYLON.Color3(1,0,0,1); dir2 = -4; } }); //Add applyimpulse method window.addEventListener("click", function () { var pickResult = scene.pick(scene.pointerX, scene.pointerY); pickResult.pickedMesh.material.diffuseColor = new BABYLON.Color3(0, 1, 0); sphere2.physicsImpostor.applyImpulse(new BABYLON.Vector3(0,10,-5.1), sphere2.getAbsolutePosition()); }); return scene; }; /******* End of the create scene function ******/ var scene = createScene(); //Call the createScene function // Register a render loop to repeatedly render the scene engine.runRenderLoop(function () { scene.render(); }); // Watch for browser/canvas resize events window.addEventListener("resize", function () { engine.resize(); }); </script> </body> </html>
  3. Eisha

    Slavs - slavian rpg game

    Wow great job 🙂 Keep it up
  4. I am trying to stop an object to pass through another object but the ball(centre sphere) is still going through another ball(left sphere). I am trying to slide the sphere in the middle towards the left in speed as soon as it collides with the pink sphere. I have tried how to increase decrease speed of the blue sphere but it still passes though the centre sphere. My source code file is attached and can be found below. Please help me. Thank You 3d.zip
  5. Eisha

    Reversing an object in babylon js

    Hello @timetocode Thank you so much for your help its a great explanation 🙂 Very well explained Thank You
  6. Eisha

    Reversing an object in babylon js

    Hello @NasimiAsl Thank You 🙂
  7. I am trying to reverse the direction of a sphere as soon as it touches the ground. I have tried every possibilities to try reverse the direction and I want it to bounce up and down starting from the ground to go upward and then coming back down. I am not understanding how to do it. Below is the code for that part. Please help me. Thank You var originalVelocity = -.005; scene.registerAfterRender(function () { sphere3.position.y = sphere3.position.y + originalVelocity; if (sphere3.intersectsMesh(ground, true)) { sphere3.material.diffuseColor = new BABYLON.Color3(1, 0, 0); sphere3.position.y = sphere3.position.y - 4*originalVelocity; //this line is not working } });