Here is the code I use for setup:
Code: Select all
public BepuTankInput(Vector3 position, ConvexHull shape, Space owningSpace)
{
this.Space = owningSpace;
RigidTransform t = RigidTransform.Identity;
// shape.CollisionInformation.LocalPosition = new Vector3(0, -.7f, 0);
shape.Position = (position); //At first, just keep it out of the way.
Vehicle = new BEPUphysics.Vehicle.Vehicle(shape);
var bb = shape.CollisionInformation.BoundingBox;
#region RaycastWheelShapes
//The wheel model used is not aligned initially with how a wheel would normally look, so rotate them.
MaximumDriveForce = 450;
BaseSlidingFriction = 0.995f;
float sus_damping = 100f;
float sus_stiffness = 400f;
int num_wheels_per_side = 4;
int one_over_nwps = 1 / num_wheels_per_side;
// positions relative to centre of tank of wheels on each side
float[] positions = { -1f, -0.5f, 0f, 0.5f, 1f };
Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2);
foreach(var p in positions)
{
var toAdd = new Wheel(
new RaycastWheelShape(.375f, wheelGraphicRotation),
new WheelSuspension(sus_stiffness, sus_damping, Vector3.Down, 1f, new Vector3(-4.3f, -0.5f, p * 4f) ),
new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce),
new WheelBrake(BaseSlidingFriction, BaseSlidingFriction, 1.0f),
new WheelSlidingFriction(0.5f, 0.6f)
);
Vehicle.AddWheel(toAdd);
leftTrack.Add(toAdd);
}
foreach (var p in positions)
{
var toAdd = new Wheel(
new RaycastWheelShape(.375f, wheelGraphicRotation),
new WheelSuspension(sus_stiffness, sus_damping, Vector3.Down, 1f, new Vector3(4.1f, -0.5f, p * 4f)),
new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce),
new WheelBrake(BaseSlidingFriction, BaseSlidingFriction, 1.0f),
new WheelSlidingFriction(0.5f, 0.6f)
);
Vehicle.AddWheel(toAdd);
rightTrack.Add(toAdd);
}
#endregion
foreach (Wheel wheel in Vehicle.Wheels)
{
//This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes.
wheel.Shape.FreezeWheelsWhileBraking = true;
//By default, wheels use as many iterations as the space. By lowering it,
//performance can be improved at the cost of a little accuracy.
wheel.Suspension.SolverSettings.MaximumIterations = 4;
wheel.Brake.SolverSettings.MaximumIterations = 4;
wheel.SlidingFriction.SolverSettings.MaximumIterations = 4;
wheel.DrivingMotor.SolverSettings.MaximumIterations = 4;
}
}
How can I avoid a vehicle rearing up (all wheels appear to still be on the ground, but the front ones arent getting good contact) or alternatively, ensure I can still steer while the vehicle is "reared" (the rearing behaviour actually looks quite cool, i'd prefer to be able to keep it in but not have any steering difficulties)