I am creating a Car Race Game, Where i need help in Car over some rough surface area by Box2d Javascript.
Question:
So please help me, how to go with that. i found IsSensor, but that is not working. So please let me know, how to go with this.
Aahhhh... Finally Got the solution from stackoverflow itself. here it is.
How to detect collision but do not collide in box2d?
i was using wrong keyword. its is
fixturedef.isSensor = true;
Thats It ;) and to detect the collision we have to write the listener like this
world.SetContactListener(listener);
var listener = new Box2D.Dynamics.b2ContactListener;
listener.BeginContact = function(contact) {
// console.log(contact.GetFixtureA().GetBody().GetUserData());
div = document.getElementById("textUI");
div.innerHTML = "Come "+contact.GetFixtureA().GetBody();
defaultCarSpeed = defaultCarSpeed/2;
}
listener.EndContact = function(contact) {
// console.log(contact.GetFixtureA().GetBody().GetUserData());
div = document.getElementById("textUI");
div.innerHTML = "Go "+contact.GetFixtureA().GetBody();
defaultCarSpeed = defaultCarSpeed*2;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With