Results 1 to 3 of 3

Thread: WebGL physics - collision detection

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    3

    WebGL physics - collision detection

    Hi there,

    I'm making a 3D free kick game in WebGL, and I am having some problems with the physics engine / collision detection. Let me show you the phenomenon (runs in Chrome):

    A correct rebound:

    http://dl.dropbox.com/u/14670704/correct/index.html

    An incorrect rebound:

    http://dl.dropbox.com/u/14670704/incorrect/index.html

    It seems that the ball does not get out of the colliding state, so when there is a check for collisions for the second time, the ball gets wrong velocity values.

    The ball gets updated every 15 ms - `index.html` - line 305:

    Code :
        if (elapsed > 15) {
            ball.update(0.015);
        }

    Collision check can be found in `ball.js` and `collision.js`.

    I've found that changing it to 10 ms sometimes solves the problem, but not in all cases. Feel free to ask if you need more information!

    Please help me solve this! I've been stuck with this for a while :\

  2. #2
    Junior Member
    Join Date
    Apr 2011
    Posts
    3

    Re: WebGL physics - collision detection

    Finally i've found it out:

    The 'Adjust ball position if overlapping triangle' code was wrong. It adjusted the ball, but in the wrong direction, so I had to negate that normal:

    Code :
    if ( vec3.length(sphereTriagDist) < this.radius ) {
        var scaledNorm = vec3.create();
        vec3.scale(tNorm, this.radius, scaledNorm);
        vec3.negate(scaledNorm, scaledNorm); //ADDED
        vec3.add(closePoint, scaledNorm, this.pos);
    }

    I've also set the update time to 10ms, because the source used a sphere radius of 0.5, and i'm using a radius of 0.1, so I need a lot more precision.

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    3

    Re: WebGL physics - collision detection

    Actually the answer is here: http://gamedev.stackexchange.com/que...lane-the-point. I had to make the normals always point in the direction of the ball.

    Scratch my last post, it's wrong.

Similar Threads

  1. 2D Game: Most Efficient Collision Detection
    By Bunkai.Satori in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 4
    Last Post: 10-15-2010, 03:50 PM
  2. Texture Based Collision Detection
    By Bunkai.Satori in forum OpenGL ES 2X - for programmable 3D graphics pipelines
    Replies: 0
    Last Post: 09-17-2010, 05:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •