简体   繁体   English

带手臂的Box2d革命联合车辆

[英]Box2d Revolute Joint vehicle with arm

I am creating vehicle like this on the image: 我正在图像上创建这样的车辆:

在此处输入图片说明

As you can see, there is: 如您所见,有:

1) main vehicle body (Red rectangle) 2) wheels 3) vehicles arm (black rectangle) 1)主体(红色矩形)2)车轮3)车臂(黑色矩形)

Arm is connected with vehicles main body using Revolute joint in shown anchor center point, this arm can be moved up and down (with following angle limits) so as you can see it can move in 90 degrees only. 臂在所示的锚定中心点通过旋转关节与车辆主体连接,该臂可以上下移动(具有以下角度限制),这样您就可以看到它只能以90度移动。

My question is, I am moving this arm by applying angular impulse, it works, I can move arm, but it keeps falling down to the default position. 我的问题是,我通过施加角度脉冲来移动该手臂,它可以正常工作,可以移动手臂,但它会一直下降到默认位置。 I am struggling how to "disable" joint, so arm can be moved only using my controller so its not affected by gravity, so player can move arm slightly up for example and arm should stay in this position, instead of falling down. 我正在努力如何“禁用”关节,因此只能使用我的控制器来移动手臂,使其不受重力影响,例如,玩家可以稍微向上移动手臂,并且手臂应保持在该位置而不是掉下。

Any help would be great, thanks. 任何帮助将是巨大的,谢谢。

The best way to disable gravity impact is to set gravityScale to zero at b2BodyDef. 禁用重力影响的最佳方法是将gravityScale处的gravityScale设置为零。 But this parameter appeared only in last versions of Box2D, and, maybe, there is no such thing in your java port 但是此参数仅出现在Box2D的最新版本中,也许您的Java端口中没有这样的东西

Anyway, your idea with gravity isn't so good I think. 无论如何,我认为您对引力的想法不是很好。 It is not physic, not realistic and you can find some related troubles because of this. 这不是物理的,也不是现实的,因此您会发现一些相关的麻烦。 For example, what if some another force, except gravity, will impact the arm? 例如,如果重力以外的其他力会冲击手臂怎么办? It will cause all the same problem. 它将导致所有相同的问题。

In my opinion, better way to make the arm - use motor of revolute joint. 在我看来,更好的制作手臂的方法-使用旋转关节马达。 Some tutorial you can find there in section "Revolute joint motor". 一些教程,你可以找到节“旋转关节运动”。 You can enable/disable motor and change its speed run-time to simulate vehicle logic. 您可以启用/禁用电动机并更改其速度运行时间以模拟车辆逻辑。 In addition, it may be useful also change run-time upper/lower limits of the joint, to prevent arm moving when no action preformed. 此外,还可以更改关节的运行时上限/下限,以防止在未执行任何操作时手臂移动。 Another way to achieve this - set motor speed to zero, that will transform motor into some kind of friction force. 实现此目的的另一种方法-将电动机速度设置为零,这会将电动机转换为某种摩擦力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM