calculate box2d impulse for a certain angle of impact

后端 未结 1 460
花落未央
花落未央 2021-01-16 13:22

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 trampoli

1条回答
  •  悲&欢浪女
    2021-01-16 13:47

    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)
    

    0 讨论(0)
提交回复
热议问题