MacSkelly Posted April 6, 2017 Share Posted April 6, 2017 I'm making a game where there's a single sphere in the middle of the screen and random spheres move in and out and you have to press a key when a sphere intersects the sphere in the middle. If you press it at the right time the score should increase. I have it working with one but once I tried to implement it with multiple spheres the score started to increase whenever you pressed key even if the spheres aren't intersecting. Here's my code: RhythmGame.init() var scene = RhythmGame.scene; var stillMesh = scene.getMeshByID("SphereStill"); var sphere1 = scene.getMeshByID("Sphere1"); var sphere2 = scene.getMeshByID("Sphere2"); var sphere3 = scene.getMeshByID("Sphere3"); var sphere4 = scene.getMeshByID("Sphere4"); var sphereArray = [sphere1, sphere2, sphere3, sphere4] var tunnelMesh = scene.getMeshByID("tunnel"); setInterval(function(){ scene.beginAnimation(sphereArray[Math.floor(Math.random() * (3 - 0 + 1)) + 0], 0, 100, true); }, 1500); $('#canvasZone').keypress(function(){ if(sphere1.intersectsMesh(stillMesh)){ RhythmGame.updateScore(); } if(sphere2.intersectsMesh(stillMesh)){ RhythmGame.updateScore(); } if(sphere3.intersectsMesh(stillMesh)){ RhythmGame.updateScore(); } if(sphere4.intersectsMesh(stillMesh)){ RhythmGame.updateScore(); } }); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 6, 2017 Share Posted April 6, 2017 Hello, do you mind creating a repro using the Playground? Quote Link to comment Share on other sites More sharing options...
MacSkelly Posted April 6, 2017 Author Share Posted April 6, 2017 I feel like a fool but I can't get it to work exactly as I have on my local machine. This is the closest I can get: http://www.babylonjs-playground.com/#1EJNKR#22 Quote Link to comment Share on other sites More sharing options...
eps Posted April 6, 2017 Share Posted April 6, 2017 (edited) I have an issue with Object to Object Collisions as well... Hmm.. Although my code, I think detects a collision and then re-detects the collision.. Actually I think I should be using this : I'll have to go away and give it a go. Edited April 6, 2017 by eps Found a link which seems to resolve my issue Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.