1
\$\begingroup\$

I want two objects, when collided, to not effect each other in velocity or force.

I have looked up guides and they say to change the PreSolve so that b2Contact.SetEnabled is false... which in code is

b2Contact.SetEnabled(false);

However, SetEnabled is a prototypal method for b2Contact, which means I have to instantiate a new b2Contact each time in order to call SetEnabled.

This does not make any sense to me and the code is wrong as right now all the objects in my world still collide with each other, even though I set that every single object will not collide with every other object:

This is my modified PreSolve method:

 B2.b2ContactListener.prototype.PreSolve = function (contact) {
        var a = contact.GetFixtureA().GetUserData();
        var b = contact.GetFixtureB().GetUserData();

        if (a instanceof Entity.Rock && b instanceof Entity.Player) {
            new B2.b2Contact.SetEnabled(false);
        }


        if (a instanceof Entity.Rock) {
            new B2.b2Contact.SetEnabled(false);
        }

    }.bind(this);

Any tips on how to use this API would be much appreciated!

\$\endgroup\$
1
\$\begingroup\$

Ok, I'm pretty stupid, but yeah the answer is to PUT THE CONTACT:

contact.SetEnabled(false).

I keep reading box2d docs for C++ and the like and keep getting tripped up on how these methods work.

this is pretty much a DUH thing once I understand it though, sorry for asking/

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.