Jump to content

Jumpthrough platforms causing bouncing


NumberOneRobot
 Share

Recommended Posts

I'm trying to create a game that involves platforms I can jump through and land on top of. However, when I jump through a platform and land on it, I bounce on top of the platform. The bouncing has to do with the height I dropped from onto the platform.

 

In order to do the jumpthrough platforms, I used the ideas from this thread, and modified them to work with my game. The actual code I'm using in the onPreSolve method is below:

world.on('preSolve', function(presolve) {		    for (var i = 0; i < presolve.contactEquations.length; i++) {		        var c = presolve.contactEquations[i]		        var f = presolve.frictionEquations[i];		        if (c.bodyA.shapes[0].collisionGroup == GROUND || c.bodyA.shapes[0].collisionGroup == PLATFORM) {		            var yAxis = p2.vec2.fromValues(0, 1);		            var y = p2.vec2.dot(c.normalA, yAxis);		            if (y >= 0){  // check for jumpthrough object // check if moving upwards		                c.enabled = false   //disable contactEquation		                if (f) {		                	f.enabled = false   //disable frictionEquation (solves the stuckInPlatform problem)		                }		                if (c.bodyA.velocity[1] < 15 ){ // velocity < 15 - still inside the platform		                    c.bodyA.velocity[1] -= 5;     // course correction!		                } 		            }		        }		    }		});

The only thing that seems like it might be causing the issue would be the course correction, though I wouldn't expect that code to be executed when I am falling and land on top of a platform, since this should check if it is moving upwards on contact. If this is a common problem, please point me to the thread where I can read more about this, because I wasn't able to find it through searches.

 

I've attached a video showing the bouncing. It's more slight in the video than usual, but sometimes it gets to the point that the character is bouncing higher than he is tall.

 

(I apologize for the poor video quality, don't have any screen recording software installed on this computer.)

IMG_1733.MOV

Link to comment
Share on other sites

c.bodyA is your platform.. that's right.. the course correction should be applied to bodyB then..     

 

be aware that the bodies that are reported are sometimes the other way around.. so sometimes it will happen that bodyB is ground and bodyA is the player.. depending on which body reports the collision.. i guess..   therfore i would probably ask for both possibilites in onpresolve() 

 

:)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...