Box2d create breakable joints for dynamic body - c++

Have been working on building a Bridge builder using box2d.
Basically you build a bridge and stress test it by passing objects on top of it. The joints break if the stress applied is high.
Can you please help how best to join the b2Body. Have tried revolute joint, but they are not breaking. Any suggestions.
Thanks

"You can get the reaction force and torque off the joint. You can query these forces after each time step and destroy the joint when your threshold is exceeded." - Quote from Erin Catto - http://www.box2d.org/forum/viewtopic.php?f=3&t=1079

I think the joints will not break by themselves. You have to break them using DestroyJoint function. You can setup b2ContactListener and get the impulse velocity of the object that hits your bridge and you can take the decision if you want to break the joint or not.

Related

Prevent collisions applying impulse in Bullet physics

I am developing third-person shooting game using Bullet and Ogre. When the character model collides with an object in the world, such as a power-up, the collision applies a force to the character and causes them to spin. How can I prevent the collision applying a force to the character?
I have set a method for btDynamicsWorld::setInternalTickCallback and so I know which bodies are colliding and the btManifoldPoint.
Note that I applyTorque to the body in order to rotate them smoothly so I cannot simply prevent rotation.
Thanks for your help.
I am unfamiliar with the physics engines you mentioned, but I know a thing or two about real physics...
Basically if you draw a free body diagram and arrows that represent the forces, you can determine the net effect. Or if you know the desired net effect, you can figure out where you need to add forces or remove forces.
You could add an equal and opposite force/torque at the time of impact. This would make the net forces on your object zero.
Or you could take the elements that are causing the forces and make them massless. Force = mass * acceleration. If the mass is zero and your physics engine is based on real world physics, then it shouldn't cause any net forces on collision.
Hope that helps.

How do I give a Box2d Kinematic body a predefined curved path

I'm new to using Box2d and really can't find a consistent answer to my question so please excuse me.
I'm writing a game for the iPhone -- who isn't these days -- and I'm using Cocos2d and Box2D. I have objects that move around in the game and I would like to give them a more of a curved path. From my studies I know that I should use body of type b2_kinematicBody which allows me to change the linear velocity every tick and keeps them from colliding with my other flying bodies. I do understand that if I know my current position (x,y) and my next position in the step (x1,y1) I would be able to compute the vector for velocity. Does anybody have a good way to give an object a defined curved path? I'm thinking it has to be some kind of parametric equation.
Take a look at bezier curves. After curve defenition you can compute the derivative (it's easy for bezier) and use it as a velocity for your body
OH whats the game called? sounds like a good one. have you looked into maybe just doing that in version 2.0

sprite hit a wall or another sprite

i am trying to understand how to implement the physics of sprite when it hit a wall.
lets say i have a wall, and a sprite is is hitting the wall with velocity and gravity using box2d(cocos2d), what is the simplest way to apply a physics of what happen next to the hit, regrading the velocity,gravity,angle of collision, etc ? contact listener ? do i have to calculate what happen next by my self and apply a new speed and force to the body ??
or box2d does it for me ?
any direction would be great.
thanx.
box2d calculates everthing for you. You don't have to worry about what happens after two bodies collide.
If your body hits ground it will bounce as its natural response. You dont have to apply a new force opposite to the gravity. All calculations are done by box2d physics engine. Physics engines are made for that.
In addition to this, if you want you can apply your own forces or impulses like below. It is up to you.
b2Vec2 force = b2Vec2(100, 200);
yourBody->ApplyLinearImpulse(force, yourBodyDefinition.position);

How to achieve falling effect in cocos2d without physics

I want to show an effect of falling blocks which settle down at pre-determined position after some falling animation.
Can this be done without using physics engine?
I found a better and easier way to do this in cocos2d by using CCJumpTo action
CCActionInterval *jump1 = [CCJumpTo actionWithDuration:3 position:sp.position height:150 jumps:2];
sp.position = ccp(10,100);
[sp runAction:jump1];
Where sp is the CCSprite for the block.
All you need is to simulate gravity, the acceleration of the object. This could be achieved quite easily with a custom animation curve. Please have a look at this QA "how-to-create-custom-easing-function-with-core-animation", which shows a way to create the curve you need. Here is some more about "Animation Types Timing" by Apple.
The function you are looking for is called
functionWithControlPoints, which has four input parameteres, so yes you can put in any random element you wish with a custom curve.
"Easing" is your answer. You can choose the method that you need visually from the links below.
Tim Groleau's easing generator
jQuery Easing Demos

box2d ship-game beginner questions: applyForce, gravity + water

I'm just starting with cocos2d + box2d.
I would love to create a simple 2d ship game where you look from top(from the sky) down at the sea with the ships.
Could someone give me a very very basic example, how to apply wind to my world? Do I have to applyForce to each ship body?
And what about the gravity? Since it goes straight down, should I set it to 0? gravity.Set(0.0f, 0.0f)? It actually would pull down the ship..
Should I somehow deal with the water? e.g with density of it?
you would probably have to detect where the ships are and then apply force on them somehow.
and yes set gravity to 0.
and water wouldn't have to be an object at all. just like a background image.
If you are looking from the top and want to apply wind force to all your ships you can use gravity vector. In this case wind force will be applied to your objects automatically.
If there are other dynamic objects on the scene then it's a good idea to keep the list (std::list or NSMutableArray) of pointers to all your ships. Notice, that by default box2D is clearing all the forces each simulation step. You can disable this property or apply forces manually each simulation step