It looks like you're new here. If you want to get involved, click one of these buttons!
contact->SetEnabled(false);
From box2d manual regarding pre-solve,
I have checked orx source, Pre-Solve and Post-Solve are not implemented, even if they are added there is no way to access box2d b2Contact data afaik.This gives you a chance to disable the contact based on the current configuration. For example, you can implement a one-sided platform using this callback and calling b2Contact::SetEnabled(false).
The contact will be re-enabled each time through collision processing, so you will need to disable the contact every time-step. The pre-solve event may be fired multiple times per time step per contact due to continuous collision detection.
//m_flags |= e_enabledFlag;
Then in BeginContact() disable contact, this would now work because box2d is not re-enabling collision for this contact in each step.
contact->SetEnabled(false);
But have to make sure that in EndContact(), collision for this contact is re-enabled, by calling this
contact->SetEnabled(true);
Second solution seems easier, and must be less expensive than the first one. But I don't see anyway to access the box2d contact data, as orx physics contact are custom listener.
Comments
The old way was to simply deactivate collision with one-way platforms when a character is going up.
That can be done in quite a few different ways, one of the simplest is probably to have a different collision flag on one-way platforms and on "hard" ones, something like:
And during the ascension of a jump, one would change the character's collision part CheckMask using orxBody_SetPartCheckMask() to just ground and restore it to ground + oneway otherwise.
Of course this can be more data driven to handle more complex situations, but you get my drift.
The advantage is that, when reaching the peak of a jump, if the one way part is still in contact with a one way platform (you get notification because the part is active but it won't modify the dynamics as it's not solid) that means the character didn't jump high enough to reach above the one way platform.
In this case one would not set the part back to solid right away when starting to go down but will wait till that collision goes away.
Not sure if what I wrote is easy to understand, lemme know if that's not the case.
But even then, is there any reason not to provide a hook for pre solve and post solve ? To get more contact info like collision impulse or force you need contact impulse which is only possible with post solve.
http://blog.allanbishop.com/box-2d-2-1a-tutorial-part-6-collision-strength/
Box2D is only used for one implementation of the physics plugin but the interface needs to be as generic as possible.
Contact add/remove are generic, pre-solve/post-solve aren't.
Pre-solve isn't really necessary useful, unless you want to track the evolution of a contact. When a contact has just been added, you don't get more info in pre-solve compared to the add contact.
Post-solve could be interesting for the reason you mentioned: the impulse being applied to the body. However you can't modify those impulse, it's strictly for checking their values and acting upon them.
That can also be done when a contact is created as you can guess what's going to happen based on the current speed of your bodies and their attributes, such as mass. For example, if you want to get the energy of the impact, you can use the simple E = 1/2 m.v^2 formula. You can also inspect your new speed after a contact has been made and solved and act upon it (the force/impulse is easy to deduce from the current speed and the mass).
A contact is only between 2 shapes (therefore 2 bodies), never more than that: in a post-solve call, you only get information about a single contact and a single impulse.
Out of curiosity, for what purpose do you need to inspect the impulse resulting from a contact?
http://www.benoitfreslon.com/tutorial-how-to-create-a-game-like-angry-birds-in-flash-part4-create-the-pigs-and-the-collision-detectiontut
orxBody_GetPartName() to identify
orxBody_SetPartSolid() to modify
1. To get the orxBODY from an orxOBJECT, use the following method :
2. Now, to get list of orxBODY_PART of a given orxBODY :
Also don't hesitate to look at the doc folder, it'll always be up to date when you sync.
If you slightly push the black object on point A, its slowly going to fall to its side, notice it would have zero velocity. Then how to determine the force on red box ? Maybe I need to take account angular velocity too.
In the contact add, you get the contact point, you simply call orxBody_GetSpeedAtWorldPosition() with that position on the body that's "attacking".
You'll get the actual speed at that point and that's all you need to know (as energy is only dependent on that speed and the body mass).
Sorry, forgot to answer that one!
Yep, I meant to post about it on the dev group, I'll try to do that soon.
String comparison isn't really much more expensive than a simple numeral comparison in most of the case, though if you want to put your mind at peace, there could be a way to do a simple number comparison now that string are hashed and stored in a dictionary, but really that wouldn't save much.
One usage I could see is, in a platform we see some platforms begin to fall as soon as player walks onto them.
First I would make them static so gravity wont have any effect on them, as soon as player walks on them I could make them dynamic/kinematic so they would begin to fall. Sometime box2d ignores objects that were sleeping so I would make them awake if needed.
I have the feeling that having dynamic platforms wouldn't work as you'd expect as contact will continuously be updated with the character on top of it and would also influence its velocity and might become a nightmare to obtain something nice.
Kinematic, on the other hand, wouldn't apply the gravity to your platform as gravity only affects dynamic bodies.
Your best bet is probably to have them kinematic since creation and then apply a speed/acceleration, either manually or via an orxFX when need be.
As for the awake property, orx should do the right thing for you behind the scene, and you shouldn't have to worry about it.
A usage of SetBullet could be, if I am using highspeed body for bullets and when they collide with enemy they normally disappear, but if the collide with certain object or wall then bullets will either fall in the ground or stuck in the wall depending on the type of the wall. To show that bullets could not penetrate, now I could set them setBullet/HighSpeed to false, and make them static. I could do this creating a joints but simply making them static would be much easier then creating a joint.
I don't understand your user case of changing the bullet property. It's an optimization flag, removing it from of body when you want it "static" doesn't have any effect.
In this case, I'd suggest completely removing the body if you want to keep your bullet, or if you really need the body to stay (probably more likely for an arrow and not a bullet), you should create a new one and replace the old one. That's usually what is done when using physics engines which don't allow these kind of conversions. There's no need to create a joint, unless you need the specific behaviors that come with it.
Afaik, unity exposes (which uses PhysX) setting up kinematic property at runtime, they have no static property, for static purpose they use a collider. And querying if a body is sleeping, and setting collision type to discrete = no highspeed or CCD = high speed.
But whatever you said is a valid solution for the problem I proposed, yes I was talking about arrows. So, I will keep that in mind.
The awake one is also portable but the idea was to abstract it so that the user doesn't have to worry about it while doing the right thing behind the scene.
One more thing, we could add tool specific stuffs using conditional compilation, so things specific to Box2D could be added under #ifdef PHYSICS_BOX2D #endif, some engines for example cocos2d does it this way, as it has either chipmunk or box2d physics.
I'm talking about the highspeed one, not the awake one.
That does not fix the problem as the plugin API (what you see in orxPhysics.h) is generic independent from the actual plugin implementation. Having conditional compiling wouldn't help.
When you use the orxDisplay.h API, you expect the same result no matter the implementation (which is not always 100% true and irks me, but hopefully that'll be fixed later on): when on PC or iOS, you still expect the same result and not to have to modify your user code with that respect.
The idea is to prevent as much as possible the user to have to do those kind of conditional compilation on his side.
Well, end of my weekend, but I will back with questions about box2d time step, animation and scroll soon.