giorfasolini

Members
  • Content count

    11
  • Joined

  • Last visited

About giorfasolini

  • Rank
    Member

Profile Information

  • Gender
    Not Telling
  1. @gryff @Wingnut Okay, Thank you for your feedback. I'll study it out Cheers Best Regards
  2. @Wingnut @gryff Hello, Thanks for your reply. So far i have implemented physic in babylon js . However i think blender is insufficient to make maze, because what i use is physic impostor, and they cant detect a hole in blender. Here's some screenshot, as can be seen the purple one is a maze i made with blender. And physic cant detect a hole i made in blender. Is there any way to bypass or solve this? Cheers
  3. Hello again forum, i hope you have a nice day I would like to build a maze game, The maze will be generated on blender as .obj format. I know this is the code for intersect mesh for babylon mesh object, does blender use the same syntax as this ? Any advice or tips will be greatly appreciated, Thank you Cheers if (snake.intersectsMesh(box1, false)) { up = false; down = false; right = false; moving = false; }
  4. @hunts Thanks, I'll check it out
  5. Greetings Again Forum, I hope you have a nice day I would like to ask whether babylon.js support backtracking function or not to find a shortest path to one mesh ? I would like the black box to follow the sonic character for more elaborate gameplay, does babylon js support this? Any advice or reply are greatly appreciated, cheers
  6. I have managed to solve this issue, using Math.floor and Math.random My humblest apologies to the community , cheers
  7. Greetings Forum, I hope you have a great day Today, I would like to ask how to randomize position in babylon.js. I have one Apple object which i would like to randomize its position everytime i touch it. Here's a screenshot of what my game looks like. As can be seen, I am trying to randomize the apple position to make it more like point collecting game. I'm trying to follow tutorial here But the program crashed, and wont work ... Any Attention or solutions will be greatly appreciated, cheers P.S : I tried to upload it to playground, but it seems not working because my apple and sonic are on different files, hence i can only provide a screenshot to help the forum to understand my question , I'm sorry for my lack of knowledge // Creation of Apple for(var i=0; i<20; i++) { x = randomNumber(-100, 100); z = randomNumber(-100, 100); var apple2; BABYLON.SceneLoader.ImportMesh("","Finalproject/", "apple.obj", scene, function (newMeshes, particleSystems, skeletons) { apple2 = newMeshes[0]; apple2.position.x = x; apple2.position.z = z; }); }
  8. Thank you for your reply, I have managed to solve this issue, thank you for your attention @davrous , cheers P.S : I tried to upload it, however due to my apple and snake are in different files than babylon javascript file, somehow i cant reproduce the snake nor apple image object in playground. Therefore, the program wont run in playground
  9. Hello again forum, I hope you have a great day I would like to continue my snake project game, and today i have decided to make a scoreboard for each fruits eaten. However i have an issue, i cannot display a UI text on my project even though i have followed tutorial in here The program seems to crash too and wont run. Any help given is appreciated. Cheers Here's my code, i insert the URL code into createScene function. <!DOCTYPE html> <html> <head> <title>Snake Game</title> <script src="babylon.js"></script> <script src="hand-1.3.7.js"></script> <script src="babylonObjLoader.js" ></script> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <canvas id="mycanvas"></canvas> <script> var canvas = document.getElementById("mycanvas"); var engine = new BABYLON.Engine(canvas, true); var createScene = function() { var scene = new BABYLON.Scene(engine); var ground = BABYLON.Mesh.CreateGround("ground1", 100, 100, 100, scene); //var camera = new BABYLON.FreeCamera("camera2", new BABYLON.Vector3(0,5,-10), scene); /*var camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, 1, -15), scene); scene.activeCamera = camera;scene.activeCamera.attachControl(canvas); scene.activeCamera.keysUp.push(87); */ var camera = new BABYLON.ArcRotateCamera("camera",0,0,0,BABYLON.Vector3.Zero(0,10,0), scene); //var camera = new BABYLON.TouchCamera("camera2", new BABYLON.Vector3(0, 10, 0), scene); //var camera = new BABYLON.GamepadCamera("camera2", new BABYLON.Vector3(0, 15, -45), scene); //var camera = new BABYLON.DeviceOrientationCamera("camera", new BABYLON.Vector3(0, 1, -15), scene); //var camera = new BABYLON.FollowCamera("camera2", new BABYLON.Vector3(0, 15, -45), scene); //camera.lockedTarget = model; //camera.setPosition(new BABYLON.Vector3(0,5,-10)); camera.setTarget(BABYLON.Vector3.Zero(),scene); camera.attachControl(canvas,false); var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0,1,0), scene); light.intesity = 0.5; var body = BABYLON.MeshBuilder.CreatePolyhedron("body", {type: 10, size: 0.7},scene); var materialBody = new BABYLON.StandardMaterial("bodyMat",scene); materialBody.diffuseColor = new BABYLON.Color3(1,0,0); body.material = materialBody; body.position.y = 5; body.position.x = 50; body.rotation.x = Math.PI/4; body.rotation.z = .19; /*var head = BABYLON.Mesh.CreateBox("head",0.7,scene); var materialHead = new BABYLON.StandardMaterial("HeadMat",scene); materialHead.diffuseColor = new BABYLON.Color3(.5,.2,0.3); head.material = materialHead; head.position.x = -4.5; head.position.z = -3; head.position.y = 1; */ var canvas2 = new BABYLON.ScreenSpaceCanvas2D(scene, { id: "mycanvas", size: new BABYLON.Size(300, 100), backgroundFill: "#4040408F", backgroundRoundRadius: 50, children: [ new BABYLON.Text2D("Hello World!", { id: "text", marginAlignment: "h: center, v:center", fontName: "20pt Arial", }) ] }); var apple; BABYLON.SceneLoader.ImportMesh("","Finalproject/", "apple.obj", scene, function (meshes) { apple = meshes[0]; //apple.parent = sphere1; /*engine.runRenderLoop(function() { //scene.activeCamera.alpha += .01; apple.rotation.y +=0.1; scene.render(); }); */ }); var apple2; BABYLON.SceneLoader.ImportMesh("","Finalproject/", "apple.obj", scene, function (meshes) { apple2 = meshes[0]; apple2.position.x = 20; apple2.position.z = 20; }); /*var sphere1 = BABYLON.Mesh.CreateSphere("sphere1",1,1, scene); sphere1.position.y = 0.7; sphere1.material = myMaterial; var myMaterial = new BABYLON.StandardMaterial("myMaterial", scene); myMaterial.diffuseColor = new BABYLON.Color3(0, 1, 0); */ //sphere1.parent = apple; var snake ; BABYLON.SceneLoader.ImportMesh("","Finalproject/", "alphaSnake.babylon", scene, function (newMeshes, particleSystems, skeletons) { snake = newMeshes[0]; snake.position.y = 2; snake.rotation.z = -0.07; snake.rotation.y = 10; snake.rotation.x = 25; snake.position = new BABYLON.Vector3(10, 0, 0); //head.parent = snake; var isvisible = false; window.onkeyup = function(event) { event = event || window.event; var keyCode = event.which || event.keyCode; switch(keyCode) { // W key case 87: snake.rotation.y = Math.PI; snake.position.x -=3; //scene.beginAnimation(skeletons[0], 0, 60, true, 1.0); break; // A Key case 65: snake.rotation.y = Math.PI/2; snake.position.z -=3; //scene.beginAnimation(skeletons[0], 0, 60, true, 1.0); break; // S key case 83: snake.rotation.y = 25.5; snake.position.x +=3; //scene.beginAnimation(skeletons[0], 0, 60, true, 1.0); break; // D key case 68: snake.rotation.y = -Math.PI/2; snake.position.z +=3; //scene.beginAnimation(skeletons[0], 0, 60, true, 1.0); break; /*// E key case 69: if (snake.intersectsMesh(apple, false)) { isvisible = true; } break; */ // J key case 74: snake.rotation.y = Math.PI/2; break; // K key case 75: snake.rotation.y = 25.5; break; // L key case 76: snake.rotation.y = -Math.PI/2; break; // I key case 73: snake.rotation.y = Math.PI; break; } }; scene.registerBeforeRender(function(){ apple.rotation.y +=0.1; apple2.rotation.y +=0.1; if (snake.intersectsMesh(apple, false)) { apple.dispose(); } if (snake.intersectsMesh(apple2, false)) { apple2.dispose(); } /*if(isvisible == true) { apple.dispose(); } */ /*sphere1.scaling.x = 5; sphere1.scaling.y = 5; sphere1.scaling.z = 5; sphere1.position.y = 2.5; sphere1.material = myMaterial; apple.scaling.x = 0; apple.scaling.y = 0; apple.scaling.y = 0; */ }); }); return scene; }; var scene = createScene(); engine.runRenderLoop(function() { //scene.activeCamera.alpha += .01; /* if(isvisible == true) { sphere1.scaling.x = 0; } */ scene.render(); }); window.addEventListener("resize",function(){ engine.resize(); }); </script> </body> </html>
  10. @JCPalmer @gryff Thank you for your feedback, I have finally found my source of mistake, which is i forgot to join the object in blender using CTRL + J Sorry for late reply. cheers
  11. Hi Forum, First of all, i tried to create a snake game for my project, however i have encountered some difficulties. I can't make the apple dissapear upon contact / collision with the snake. I can make the object dissapear normally if its just mesh from babylon ( sphere, box, etc ) . However, when i tried to do the same to imported blender object, it doesnt work, Any ideas? Any Help given is greatly appreciated. Thank you here's my code : P.S : i tried to upload it to playground, but it seems not working, as my snake and apple are on different file, and i dont know how to upload them in playground. <!DOCTYPE html> <html> <head> <title>Snake Game</title> <script src="babylon.js"></script> <script src="hand-1.3.7.js"></script> <script src="babylonObjLoader.js" ></script> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <canvas id="mycanvas"></canvas> <script> var canvas = document.getElementById("mycanvas"); var engine = new BABYLON.Engine(canvas, true); var createScene = function() { var scene = new BABYLON.Scene(engine); var ground = BABYLON.Mesh.CreateGround("ground1", 100, 100, 100, scene); //var camera = new BABYLON.FreeCamera("camera2", new BABYLON.Vector3(0,5,-10), scene); /*var camera = new BABYLON.FreeCamera("FreeCamera", new BABYLON.Vector3(0, 1, -15), scene); scene.activeCamera = camera;scene.activeCamera.attachControl(canvas); scene.activeCamera.keysUp.push(87); */ var camera = new BABYLON.ArcRotateCamera("camera",0,0,0,BABYLON.Vector3.Zero(0,10,0), scene); //var camera = new BABYLON.TouchCamera("camera2", new BABYLON.Vector3(0, 10, 0), scene); //var camera = new BABYLON.GamepadCamera("camera2", new BABYLON.Vector3(0, 15, -45), scene); //var camera = new BABYLON.DeviceOrientationCamera("camera", new BABYLON.Vector3(0, 1, -15), scene); //var camera = new BABYLON.FollowCamera("camera2", new BABYLON.Vector3(0, 15, -45), scene); //camera.lockedTarget = model; //camera.setPosition(new BABYLON.Vector3(0,5,-10)); camera.setTarget(BABYLON.Vector3.Zero(),scene); camera.attachControl(canvas,false); var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0,1,0), scene); light.intesity = 0.5; var body = BABYLON.MeshBuilder.CreatePolyhedron("body", {type: 10, size: 0.7},scene); var materialBody = new BABYLON.StandardMaterial("bodyMat",scene); materialBody.diffuseColor = new BABYLON.Color3(1,0,0); body.material = materialBody; body.position.y = 5; body.position.x = -50; body.rotation.x = Math.PI/4; body.rotation.z = .19; var head = BABYLON.Mesh.CreateBox("head",0.7,scene); var materialHead = new BABYLON.StandardMaterial("HeadMat",scene); materialHead.diffuseColor = new BABYLON.Color3(.5,.2,0.3); head.material = materialHead; head.position.x = -4.5; head.position.z = -3; head.position.y = 1; var apple; BABYLON.SceneLoader.ImportMesh("","Finalproject/", "apple1.obj", scene, function (meshes) { apple = meshes[0]; apple.parent = sphere1; /*engine.runRenderLoop(function() { //scene.activeCamera.alpha += .01; apple.rotation.y +=0.1; scene.render(); }); */ }); /*var sphere1 = BABYLON.Mesh.CreateSphere("sphere1",1,1, scene); sphere1.position.y = 0.7; sphere1.material = myMaterial; var myMaterial = new BABYLON.StandardMaterial("myMaterial", scene); myMaterial.diffuseColor = new BABYLON.Color3(0, 1, 0); */ //sphere1.parent = apple; var snake ; BABYLON.SceneLoader.ImportMesh("","Finalproject/", "alphaSnake.babylon", scene, function (newMeshes, particleSystems, skeletons) { snake = newMeshes[0]; snake.position.y = 2; snake.rotation.z = -0.07; snake.rotation.y = 10; snake.rotation.x = 25; snake.position = new BABYLON.Vector3(0, 0, 0); head.parent = snake; var isvisible = false; window.onkeyup = function(event) { event = event || window.event; var keyCode = event.which || event.keyCode; switch(keyCode) { // W key case 87: snake.position.x +=3; //scene.beginAnimation(skeletons[0], 0, 60, true, 1.0); if (head.intersectsMesh(apple, false)) { isvisible = true; } break; // A Key case 65: snake.position.z +=3; //scene.beginAnimation(skeletons[0], 0, 60, true, 1.0); break; // S key case 83: snake.position.x -=3; //scene.beginAnimation(skeletons[0], 0, 60, true, 1.0); break; // D key case 68: snake.position.z -=3; //scene.beginAnimation(skeletons[0], 0, 60, true, 1.0); break; } }; scene.registerBeforeRender(function(){ if(isvisible == true) { apple.dispose(); /*sphere1.scaling.x = 5; sphere1.scaling.y = 5; sphere1.scaling.z = 5; sphere1.position.y = 2.5; sphere1.material = myMaterial; apple.scaling.x = 0; apple.scaling.y = 0; apple.scaling.y = 0; */ } }); }); return scene; }; var scene = createScene(); engine.runRenderLoop(function() { //scene.activeCamera.alpha += .01; /* if(isvisible == true) { sphere1.scaling.x = 0; } */ scene.render(); }); window.addEventListener("resize",function(){ engine.resize(); }); </script> </body> </html>