Jump to content

How to get the collision force on a p2 contactEquation


JakeCake
 Share

Recommended Posts

The p2 docs are not of much help to me as I am not a physics academic.

 

on the contactEquation I have this:

function _onEnter(bodyB, shapeA, shapeB, contactEquations) {            for(var i = 0; i < contactEquations.length; i++) {                if(contactEquations[i].firstImpact === true) {                    window.console.log(contactEquations[i].relativeVelocity);                }            }        }        spr.body.onBeginContact.add(_onEnter, this);

however, the contactEquations.relativeVelocity always returns 0, so I am looking for something else I believe. I need to play a sound when two objects collide, the volume will be dependant on either the relative velocity between these two objects, or even better, the total force they collide with, but I can calculate this myself with the velocities times the two bodies masses.

 

The docs I am looking at: http://schteppe.github.io/p2.js/docs/classes/ContactEquation.html#property_contactPointA

 

It seems like I may have to run some function to calculate the relativeVelocities, but I can't figure out which one as the docs only says something like: "Computes G*inv(M)*f, where M is the mass matrix with diagonal blocks for each body, and f are the forces on the bodies.", which does not make much sense to me.

 

I really hope someone can help me out here :)can't seem to find more documentation of p2 on my own.

Link to comment
Share on other sites

for (var i = 0; i < presolve.contactEquations.length; i++) {        c = presolve.contactEquations[i]        console.log(c.computeGW());

this is how you can call one of the methods and get the results..    i just don't understand what exactly those functions calculate.. the docs could really be a little bit more verbose ;)

 

 

 

edit: i forgot to say that i'm using the onPresolve event in my game to find out if some objects collide and then - if wanted - cancel the collision response completely (let them slip through each other)

if © c.enabled = false;

 

i'm telling you this because i don't know at which point you grab the equations and if there are always the same infos in it ....

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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