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开发者_如何学Go 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);
精彩评论