Car stability.

Discuss issues specific to the Flash/AS3 port of Box2D
kestorr
Posts: 32
Joined: Tue May 22, 2012 2:37 am

Car stability.

Postby kestorr » Sat Sep 29, 2012 4:04 am

Hello there.

I have constructed a car using revolute and prismatic joints.
But if i speed it on ramp the car might get upside down depending on the speed and the ramp.

So what i woudl want to do is make the car stable, no matter what ramp, no matter what speed to almost always land upside up (with the wheels on the ground).
Since im not good at math im not sure what to do. But im thinking something like this (though i might be wrong):

carbedActor.carbedBody.m_angularDamping=carbedActor.carbedBody.GetAngle(); and some math stuff im not sure of.


Could you help me on this one please?



Thanks.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Car stability.

Postby irresistible force » Sun Sep 30, 2012 8:50 am

One way might be to have another body of insignificant weight but fixed rotation, joined to the car body at the center of mass with a revolute joint. This second body would be very light so it would not affect the movement of the car, but it has infinite rotational inertia so you can set limit limits on the revolute joint to constrain the car from rotating too far in either direction. It might look a bit unnatural when the car suddenly hits the limit, and you cannot do flips etc.

Another way might be to add a weight (a second fixture) below the car body so that it tends to stay upright more easily. This will take a bit more effort in tweaking things for the right result, and it can still allow the car to land upside down.

kestorr
Posts: 32
Joined: Tue May 22, 2012 2:37 am

Re: Car stability.

Postby kestorr » Sun Sep 30, 2012 11:56 am

Howdy.
Thanks for the answer.
I also figured a way to do this.
Raise a flag in the Contact Listener and then handle in the main class:

Code: Select all


if(GameContactListener.groundTouch==false)
{
      carbedActor.carbedBody.SetAngularVelocity(Math.sin(carbedActor.carbedBody.GetAngle()) * -1);
}



So when the wheels are not touching the ground this is what happens.. it straightens the car.
But there be a problem with that.
When the wheel goes up ramp they also hit it.. and they get pushed a bit back even with 0 restitution. So i get a weird effect for a few split seconds.
So im thinkig to make a sensor stationary body that is exactly the same as the ground but only 2-3 pixels higher. And in the contact listener to associate the wheels with this sensor body.
So that ll mean the car will straigthen only when its in the air. or a bit upside the ground due to small bumps and so on.


Return to “Flash”



Who is online

Users browsing this forum: No registered users and 1 guest