计算一定角度的box2d脉冲 [英] calculate box2d impulse for a certain angle of impact

查看:102
本文介绍了计算一定角度的box2d脉冲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个球(一个圆形的动态体)在重力条件下作用于表面(蹦床)。

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.

当球撞击蹦床(从A点到B点画出图片)时,我想对球进行冲击(蹦床表面正常)。

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.

问题在于我现在使用:

 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.

推荐答案

我不读取Objective-C,但问题似乎很清楚:

I don't read objective-C, but the problem seems to be clear:

你的冲动 b2Vec2(0,[self fullMass] * [GameMaster sharedInstance] .usrTrampolineForce)实际上并不包含任何x组件!

Your impulse b2Vec2(0, [self fullMass]*[GameMaster sharedInstance].usrTrampolineForce) does not actually include any x component!

将你的冲动分成x和y分量(伪代码):

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)

这篇关于计算一定角度的box2d脉冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆