Problem when making body sensor while collision is happening.

Discuss issues specific the Java port of Box2D
Spede
Posts: 3
Joined: Mon May 01, 2017 6:47 am

Problem when making body sensor while collision is happening.

Postby Spede » Mon May 01, 2017 7:09 am

I'm using Fisica wrapper with Processing.

I have two bodies colliding. Player controlled rectangle that is pushing a circle that has big mass around. I make the rectangle sensor while it is in process of pushing the circle. Instead of the sensor passing through the circle like you would think would happen the bodies just keep colliding (rectangle pushing the circle) until the collision is over. After the collision is over and I move the rectangle (now sensor) against the circle it passes through it like it should. But it seems like there is no way to make this happen (body becoming sensor and passing through other body) while the collision is happening for some reason?

JeneaV
Posts: 3
Joined: Sun Apr 23, 2017 7:44 am

Re: Problem when making body sensor while collision is happening.

Postby JeneaV » Sun May 07, 2017 1:32 am

If you are interested to make player controlled rectangle never collide with circle go to this link to see how you can implement your own collision filtering: http://www.iforce2d.net/b2dtut/collision-filtering

Spede
Posts: 3
Joined: Mon May 01, 2017 6:47 am

Re: Problem when making body sensor while collision is happening.

Postby Spede » Sun May 07, 2017 7:22 am

Thanks for answering. I've posted this problem to another forum and nobody answered in 200 views which is probably because this is a very specific problem.

I was kind of fearing that I have to get to the nitty gritty to solve this problem. I've been doing a -- what was supposed to be a quick -- prototype of a game and that's the reason I've been using Processing and the Fisica wrapper for box2d which keeps things really simple. Now I can't really see other solution than to dust off my c++ books and also learn the real Box2d. Which I wouldn't mind at all if this wasn't just a quick prototype to test if an idea has any legs and learning processing took some time.

But it's kind of interesting that sensors work like that. They are meant to go through bodies but if a body becomes sensor while it's in contact with other body it basically stays as a body until the contact is over. The isSensor variable is true but the rectangle is still pushing the cricle around like nothing has happened. Maybe that is how it's supposed to be, but I find it strange and it has made making this prototype impossible to me.

JeneaV
Posts: 3
Joined: Sun Apr 23, 2017 7:44 am

Re: Problem when making body sensor while collision is happening.

Postby JeneaV » Sun May 07, 2017 11:52 pm

Why C++? Are you writing in Java or C++?

Actually it should not be an issue. If you want to make your rectangle go through circle you can do this:

Code: Select all

 FixtureDef rect = new FixtureDef();
 rect.shape = somePolygonShape;
 rect.filter.categoryBits = 0b0010; // I am a 0b0010
 rect.filter.maskBits = 0b0010; // I collide with fixtures who 0b0010
 body.createFixture(rect);
 ....
 
 FixtureDef circle = new FixtureDef();
 circle.shape = someCircleShape;
 circle.filter.categoryBits = 0b0001; // I am a 0b0001
 circle.filter.maskBits = 0b0001; // I collide with fixtures who 0b0001
 body.createFixture(circle);

Spede
Posts: 3
Joined: Mon May 01, 2017 6:47 am

Re: Problem when making body sensor while collision is happening.

Postby Spede » Wed May 10, 2017 9:15 am

I guess Processing is based on Java, though I don't know how much that shows. It's really simple language and I've haven't done much with it. I've programmed with both c++ and java ages ago. I guess I could go either way if I need.

Thanks for the solution, I'll try it later.


Return to “Java”



Who is online

Users browsing this forum: Bing [Bot] and 2 guests