isekream Posted April 16, 2016 Share Posted April 16, 2016 Hey guys, I am developing this draft game demo and I need some advice/ feedback on some tips to make the collision a bit better. I'm using loadPolygon to load a custom body shapes for this sprite object and responding to collisions using onBeginContact to applyImpulse to the ball on a SPACEKEY.onDown The following is the code player.body.collides(ballCollisonGroup, this.headerBall, player) headerBall(bodyA, bodyB, shapeA, shapeB, equation) { let duration = 10; let localX = equation[0].contactPointA[0]; let localY = equation[0].contactPointA[1]; let forceX = 0.12 * this.headMass; let forceY = 0.8 * this.headMass; if(this.headerKey.isDown) // only if see is down apply additional force { duration = Math.min(this.headerKey.duration, 500); // apply time based on how long key pressed forceY = (1 * this.headMass).toFixed(2); // apply force of 1 velocity x mass of head (.53) forceX = (1 * this.headMass).toFixed(2); let impulse = [(forceX * duration), (forceY * duration )]; // calculate impulse bodyA.applyImpulse(impulse, localX, localY ); // apply it to ball } } I'm not sure if I am doing it right as I am not verse in Math Physics but i would like some feedback on the following: - Is my formula accuarate? Can I set varying impulses based on the contact shape? There is a sort of glitch if the ball comes into contact with his shoes and the ball ends up in the middle of his body which gets stuck. How can I avoid this? The key down condition seems to be glitchy is there anyway to make this a bit more "safe" to detect and capture? I need to apply some force to the ball ONLY when the space key is pressed. Thank you in advance for your feedback. Link to comment Share on other sites More sharing options...
isekream Posted April 19, 2016 Author Share Posted April 19, 2016 Tough crowd..... Link to comment Share on other sites More sharing options...
smatthews1999 Posted January 24, 2017 Share Posted January 24, 2017 Sorry no one is able to comment on your post. I am also trying to understand how functions like 'applyImpulse' are used. Maybe everyone has dumped P2 for Box? Link to comment Share on other sites More sharing options...
Recommended Posts