Reputation: 1559
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)
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.
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.
Upvotes: 0
Views: 1179
Reputation: 2554
The best way to disable gravity impact is to set gravityScale
to zero at b2BodyDef. But this parameter appeared only in last versions of Box2D, and, maybe, there is no such thing in your java port
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.
Upvotes: 3