Sliding Car

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Scotty
Posts: 6
Joined: Mon Aug 03, 2009 6:13 am
Contact:

Sliding Car

Post by Scotty »

G'Day gang,

In a little game we're writing, the primary purpose is to have a Kart racing game. We have taken the dimensions from http://www.kartbuilding.net/racingkart/ ... sembly.pdf and have gone through trying to use the DEMO's as a walkthrough.

One little question before I move onto the big one. Does the compoundbody used in the demo help with putting extra weight to the back of the vechicle to stabalise it??

Now the big question, what can I do to make the kart behave more stable? (so it doesn't slide so much at every corner and have a heart attack when it hits a bump and stuff)

These are the properties I've used for the wheels:
private const float FORWARD_SPEED = 30f;
private const float BACKWARD_SPEED = 10f;

#region privateWheelVariables
private float _suspensionLen = 0.4f;
private float _suspensionConstant = 42f;
private float _slidingFricition = 0.6f;
private float _rollFriction = 0.02f;
private float _grip = 0.6f;
private float _maxSuspensionForce = 600f;
private float _suspensionDamp = 0.8f;
#endregion

and for the body of the car:
const float bodyWidth = 0.815f;
const float bodyHeight = 0.33f;
const float bodyLength = 1.59f;
const float bodyMass = 160f;
const float wheelRadius = 0.135f;
const float wheelLength = 0.2f;

and I attach the wheels like so:
//Using Convex Cast Wheels
#region Wheels
Quaternion initialWheelRotation = Quaternion.CreateFromAxisAngle(Vector3.Forward, (float)Math.PI / 2);
Entity wheelShape = new Cylinder(new Vector3(0, 0, 0), wheelLength, wheelRadius);
wheelShape.collisionMargin = 0f;
Wheel wheel;

//Front left wheel
wheel = new ConvexCastWheel(new Vector3(-0.55f, -0.141f, 0.665f), initialWheelRotation, wheelShape,
wheelRadius, Vector3.Down, Vector3.Backward, suspensionLen, suspensionConstant, slidingFriction, rollFriction, grip, maxSuspensionForce, suspensionDamp);
this.vehicle.addWheel(wheel);
new Display.DisplayWheelModel(wheelModel, wheel);

//Front right wheel
wheel = new ConvexCastWheel(new Vector3(0.55f, -0.141f, 0.665f), initialWheelRotation, wheelShape,
wheelRadius, Vector3.Down, Vector3.Backward, suspensionLen, suspensionConstant, slidingFriction, rollFriction, grip, maxSuspensionForce, suspensionDamp);
this.vehicle.addWheel(wheel);
new Display.DisplayWheelModel(wheelModel, wheel);

//Back left wheel
wheel = new ConvexCastWheel(new Vector3(-0.55f, -0.141f, -0.665f), initialWheelRotation, wheelShape,
wheelRadius, Vector3.Down, Vector3.Backward, suspensionLen, suspensionConstant, slidingFriction, rollFriction, grip, maxSuspensionForce, suspensionDamp);
this.vehicle.addWheel(wheel);
new Display.DisplayWheelModel(wheelModel, wheel);

//back right wheel
wheel = new ConvexCastWheel(new Vector3(0.55f, -0.141f, -0.665f), initialWheelRotation, wheelShape,
wheelRadius, Vector3.Down, Vector3.Backward, suspensionLen, suspensionConstant, slidingFriction, rollFriction, grip, maxSuspensionForce, suspensionDamp);
this.vehicle.addWheel(wheel);
new Display.DisplayWheelModel(wheelModel, wheel);

I'm aware my 'display' objects attach themselves to the game's components list in global variables when they're constructed, so don't have too much of a heart attack when you see the weird 'new's being used :P Ok, third question, If I seperate my terrain into seperate models, and I have one section I load in as 'ice', can I just set the StaticTriangleGroup's friction property to 0f or -0.3f or something to achieve this? or is there a better way?

Thanks so much in advance,
Scotty
User avatar
Zukarakox
Not a Site Admin
Posts: 426
Joined: Mon Jul 10, 2006 4:28 am

Re: Sliding Car

Post by Zukarakox »

Using compound bodies to redistribute weight could help in balancing the kart, adjusting the bounciness, friction, and linear/angular damping settings could also help, depending on your simulation. From the videos you have posted on your team's blog, you might want to try increasing the friction of the ground/wheels and increasing the strength of gravity (or adding a downward force) so the car stays anchored to the ground.

Splitting the terrain into multiple models is an easy way to set different sections to have different physical properties. You could also build a custom content importer and plugin for your modeler so the artist can apply different physical values, or you could extract triangles individually from the mesh parts of the model, and then build multiple StaticTriangleGroups from the same model, applying different physical properties based on the name of the mesh part.

Setting friction to 0 should simulate ice, negative numbers may result in odd things happening. (Physics may clamp the values now, it has been awhile since I've used them) You could also check to see if the kart is currently on the ice using a raycast and then apply impulses to the back of the car for a 'fishtailing' effect when steering.
i has multiple toes
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Sliding Car

Post by Norbo »

The reason the car body is compound in the demos is more for looks than anything. The top part weighing down the tires can help with certain effects, but it mainly just caused the car to fishtail before I reduced its mass significantly.

That said, using a compound body can help fine tune the mass distribution like Zukarakox mentioned. You can just use a normal object if you want (like a box in the attached example).

I assume you're going for a pretty arcadey go kart feel. Generally this means a quick steering response with very little rolling. To allow for quick steering, the sliding friction needs to be increased significantly. However, with a high top speed/acceleration on the default demos car, you'll be doing barrel rolls in no time. Instead, the body should have a much lower center of gravity- much like a real go kart. You could spend some time creating a fairly realistic representation (a weighty frame and engine extremely close to the ground, basically hanging below the wheels) using a CompoundBody, but generally it's quite a bit easier just to make some tweaks to a simple box.

In the attached demo, the box is kept just barely above the ground by a short, stiff suspension. The suspension damping is very high to prevent oscillatory/bouncy movement. In addition to being pretty low to the ground, the box's center of mass is offset even further down. For this example, I removed the upright constraint to show that it is able to keep itself oriented without any help.

Another minor note: try to keep your wheels' starting locations inside of the vehicle body. If they are exposed, it's possible for the car to oddly climb vertical surfaces, or slide horizontally at high speeds once it gets turned onto its side.



The StaticTriangleGroup uses vertices of type StaticTriangleGroupVertex. These have fields for friction and bounciness. There are a variety of ways to get the values into these fields as Zukarakox mentioned. Vehicle wheels have a frictionType field as well which can be set to define how the car combines the wheel's friction with the ground's friction. If you want the ground to have total control, you could set the wheel's frictionTypes to WheelFrictionTypes.maxFriction, set the wheel's friction to zero, and set the ground triangle's frictions to whatever feels right in each area.

Let me know if you have any questions.
Attachments
VehicleInput.zip
(2.76 KiB) Downloaded 323 times
Scotty
Posts: 6
Joined: Mon Aug 03, 2009 6:13 am
Contact:

Re: Sliding Car

Post by Scotty »

That works very great thanks! :)

We'll post up some videos of the game as it stands soon. Just a quick question, occasionally, if the car is flying through the air, then hits the ground (where, I assume two polygons join), it will come to a halt, as if it's hit a brick wall. This is hard to replicate but I'm just wondering if there's any solutions to something like this?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Sliding Car

Post by Norbo »

You could try fiddling with the (StaticTriangleGroup).tryToUseTriangleNormals and (StaticTriangleGroup).useFaceNormalWithinAngle fields. The first one should be enabled by default, while the second one defines how widely the mesh should use the triangle's normal as opposed to an edge normal during a collision.

Since your cart is likely hitting the 'side' of the triangle and generating a near-horizontal contact, it comes to a sudden halt. If you make the useFaceNormalWithinAngle large enough, it will continue using the triangle's normal even when the collision is on the side of the triangle, preventing the collision response system from halting your horizontal motion.

The reason why this value isn't all-encompassing to begin with is that, sometimes, getting a normal that isn't the triangle's normal is needed for accurate collision. You probably won't see any side effects unless you have a rotation-locked object, which may rest in an unintuitive way near triangle edges.
Post Reply