问题
I have a ball (a dynamic body in the shape of a circle) that acts on a surface (trampoline) in the conditions of a gravity force.
When the ball impacts the trampoline (drawn in the picture from point A to B) I would like to apply an impulse (normal to the trampoline surface) to the ball.
The problem is that right now i use:
b2Vec2 impulse = b2Vec2(0, [self fullMass]*[GameMaster sharedInstance].usrTrampolineForce);
b2Vec2 impulsePoint = _body->GetWorldPoint(b2Vec2(0/PTM_RATIO, -1.0/PTM_RATIO));
_body->ApplyLinearImpulse(impulse, impulsePoint);
Which sends the ball perpendicular(on the surface) up (the red direction in the drawing), although it should respect a certain realistic trajectory (drawn with black).
How can i apply the impulse to have a realistic jump?
i.e. Note that i am interested in all the cases of the ball intersection. for example, the ball could drop on the trampoline and the ball should still have a correct trajectory.
回答1:
I don't read objective-C, but the problem seems to be clear:
Your impulse b2Vec2(0, [self fullMass]*[GameMaster sharedInstance].usrTrampolineForce)
does not actually include any x component!
Split your impulse into x and y components (pseudocode):
Impulse_magnitude = Ball_mass * Trampoline_Force
# theta is the angle between the horizontal and your impulse
# this will depend on the angle of the trampoline.
Impulse_x = Impulse_magnitude * Cos(theta)
Impulse_y = Impulse_magnitude * Sin(theta)
# Create your impulse vector
Impulse_v = b2Vec(Impulse_x, Impulse_y)
来源:https://stackoverflow.com/questions/9924640/calculate-box2d-impulse-for-a-certain-angle-of-impact