[英]Box2d strange applyLinearImpulse
I have two dynamic body. 我有两个动态的身体。 At each step i try set const velocity for this bodies. 在每一步中,我都尝试为此物体设置恒定速度。 Exist three variant how do this: 存在三种变体该如何做:
body.applyLinearImpulse(Helper.getVec(config.getLinearVelocity()*body.getMass(), body.getAngle()), body.getPosition());
or 要么
body.applyForce(Helper.getVec(config.getLinearVelocity()*body.getMass(), body.getAngle()), body.getPosition());
or 要么
body.setLinearVelocity(Helper.getVec(config.getLinearVelocity(), body.getAngle()));
where config.getLinearVelocity()
return value V
for first body and 1.5*V
for second body. 其中config.getLinearVelocity()
返回第一个主体的值V
,第二个主体返回1.5*V
If i call setLinearVelocity
on each step, then bodies normally move, each with own speed. 如果我在每一步上都调用setLinearVelocity
,则物体通常会以各自的速度移动。 But if i call other functions on each step, bodies move at the same speed, at that their velocity is several times higher than if use setLinearVelosity
. 但是,如果我在每个步骤上调用其他函数,则物体以相同的速度运动,因为它们的速度是使用setLinearVelosity
的速度的setLinearVelosity
。 Why? 为什么?
You have to call applyLinearImpulse only once, because when you call this function, the mouvement will be decomposed in multiple steps. 您只需调用一次applyLinearImpulse,因为调用此函数时,移动将分解为多个步骤。 For example, if you want to make a player jump, you call applyLinearImpulse() on its body only 1 time (when you touch the screen for example) and box2d will increase de velocity, then the gravity force will decrease it. 例如,如果您想让玩家跳起来,只需在其身体上调用applyLinearImpulse()1次(例如,当您触摸屏幕时),而box2d将增加速度,则重力将减小速度。
On the other hand, setLinearVelocity will set the velocity just for the current step of the world 另一方面,setLinearVelocity将仅针对世界的当前步骤设置速度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.