Jump to content

intersectsMesh keeps resulting in true


MacSkelly
 Share

Recommended Posts

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();
    }
});

 

Link to comment
Share on other sites

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 by eps
Found a link which seems to resolve my issue
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...