Box2D Forums

It is currently Mon May 20, 2013 11:59 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Huge mass diffrences?
PostPosted: Sat Jun 05, 2010 12:17 pm 
Offline

Joined: Mon Sep 17, 2007 8:29 am
Posts: 12
Hi forum :)!

Is it possible to create a body that doesn't push other bodies around, but respects their boundaries? I want all the collision reaction remain on the side of one body and if the collision forces on the body are unsolvable, get the information about being "squished".

As if one body would have an infinitely small mass and the other's mass would be gigantic.
As if big bodies would be only a static geometry from the small bodies perspective, but would interact between themselves like normal physical bodies.

I tried with mass differences, but - as I am using mouse joint - I either can't precisely control the small body, or have the small body push big bodies around. These are always tiny pushes in extreme situations, but still noticeable.

I'm using AS3 version of box2d and would prefer solution applicable in this version, but any tips can help.


Top
 Profile  
 
PostPosted: Sun Jun 06, 2010 12:02 pm 
Offline

Joined: Mon Sep 17, 2007 8:29 am
Posts: 12
Ok, I browsed forum for similar problems and found no satisfying solution. One mentioned switching "big bodies" state between static and dynamic, but it seemed a bit hacky and would not give any info about squishing the "small body".

I want to use box2d for collision detection only, but solve the contacts within my own code. How?

1)A player body collects the collision info (contacts and penetration depths?)
2)All the contact are cancelled
3)collision response is made from within my own code and the "squish test" is executed
4)A player body's position is updated to a newly established position

Any tips?


Top
 Profile  
 
PostPosted: Sun Jun 06, 2010 2:40 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
I'm confused. First you say you want some contact ranking, then you say you want to implement your own solver. So which is it?

For the first one you can write some code to flag the contact as one-sided, then in the contact solver you would set the inverse mass and inertia to zero for the immovable body.

For the second one, you would not use anything in the dynamics folder and just use the structures and algorithms in the collision folder. By design, nothing in the collision folder depends on anything in the dynamics folder.


Top
 Profile  
 
PostPosted: Sun Jun 06, 2010 3:58 pm 
Offline

Joined: Mon Sep 17, 2007 8:29 am
Posts: 12
I'm prototyping a game idea and seek to achieve the functionality I need by these two different means - either from inside of box2d by using one sided contacts or by handling player body with my own collision reaction. These are two solutions I am exploring.

Quote:
For the first one you can write some code to flag the contact as one-sided, then in the contact solver you would set the inverse mass and inertia to zero for the immovable body.

I found this solution in the forum. It would mean modifying the source, or does box2d provide some functionality for doing that from the outside?

I would make a flag on a contact alongside sensor/continuous/touching flags in b2contact?
Then in b2ContactSolver, every time invmass appears, check for this flag and make zero if this flag appears?
The same with inertia?
How would I make sure that all the contacts generated with player body would have this specyfic flag?

Quote:
For the second one, you would not use anything in the dynamics folder and just use the structures and algorithms in the collision folder. By design, nothing in the collision folder depends on anything in the dynamics folder.

The point is box2d collision reaction fits fine for most of bodies in my game, but I would like to process the player body differently. Get the contacts from the "dummy" player body, but do not execute them inside the box2d step and process them myself instead.

Hope that's clear enough :).


Top
 Profile  
 
PostPosted: Mon Jun 07, 2010 12:07 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
yfan wrote:
I found this solution in the forum. It would mean modifying the source, or does box2d provide some functionality for doing that from the outside?


This is not in Box2D and I don't have any plans to implement it.

yfan wrote:
I would make a flag on a contact alongside sensor/continuous/touching flags in b2contact?
Then in b2ContactSolver, every time invmass appears, check for this flag and make zero if this flag appears?
The same with inertia?
How would I make sure that all the contacts generated with player body would have this specyfic flag?


That sounds right. You just need to flag the contact when it is created (via the listener). You only want to set invMassA or invMassB to zero, not both.


Top
 Profile  
 
PostPosted: Mon Jun 07, 2010 9:16 am 
Offline

Joined: Mon Sep 17, 2007 8:29 am
Posts: 12
Ok, I went with your advice and used contact listener to flag contacts made by player body as one sided and then in contact solver I set the invmass and invi of body A or body B to zero. It seems to work "somehow", but:

-in some situations player can still push the bodies - does it occur somewhere outside contact solver, or maybe something other than invI and invMass matters here?
-the collision response is wrong - steering the player body to the inside of another body doesn't result in player body staying steadily on the big body's edge, but instead it jumps like crazy.
-if the body doesn't jump, it glues itself to the edge. Taking it away uses significantly more force than pushing it before making contact.
-flagging the b2contact wasn't enough as some places from which collision solver manipulates invmass and invI have no access to contact (only to contact contstraint which doesn't store ref to contact).

The result can be seen at:
http://megaswf.com/view/2abe1a76a225d4b ... 5fc4a.html

Did anyone made something similar and can point me my wrongs? Am I missing something important?


Top
 Profile  
 
PostPosted: Mon Jun 07, 2010 9:45 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
You probably need to make a similar change to the TOISolver.


Top
 Profile  
 
PostPosted: Mon Jun 07, 2010 11:09 am 
Offline

Joined: Mon Sep 17, 2007 8:29 am
Posts: 12
I'm using Box2dAS3, there is no TOIsolver.

Making player body a bullet helped with most of the collision response jumps.


Top
 Profile  
 
PostPosted: Mon Jun 07, 2010 4:29 pm 
Offline

Joined: Mon Sep 17, 2007 8:29 am
Posts: 12
Now I'm trying the second approach: a player body collects contacts, but contact listener disables them all. I get the list by Player.GetContacts() and then want to process them by myself.

I want to process position of a player only and modify it so it does not collide with any shapes. Assuming player is a circle, I would need a nearest edge from each contact and from that I can easily calculate a proper position - get the distance and if greater than radius move the player according to edge normal; repeat for each contact.

I assume this kind of information would be stored in a contact manifold, but i don't get it yet and don't know how to extract it. How can I do that? And does it really work like that in box2d :)?


Top
 Profile  
 
PostPosted: Wed Jun 09, 2010 4:06 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
This second approach is not bad at all. This is what I use in games. The player is not rigid body. I just collect contacts and solve them according to game design rules. You can extract the contact points using b2WorldManifold. Take a look at the manual and testbed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group