Isolating parts of the simulation? There isn't much more yet then this Tick function in both applications, one is fed by the windows message pump, the other by WPF's composition target.
These snippets are all that is related to bepu. The vehicle itself is loaded from a file in both situations:
Code: Select all
var wheels = new Wheel[wheelCount];
for (int i = 0; i < wheelCount; i++)
{
var localWheelRotation = Quaternion.RotationAxis(new Vector3(0, 0, 1), MathHelper.PIOver2); // the rotation that is applied to "roll" the wheel, correct?
var graphicWheelTransform = Matrix.RotationZ(wheelDefinition.SuspensionAttachment.X > 0 ? MathHelper.PIOver2 : -MathHelper.PIOver2); // same mesh used for left & right wheels, so rotate 180°
var shape = new CylinderCastWheelShape(wheelDefinition.Radius, wheelDefinition.Width, localWheelRotation, graphicWheelTransform, true);
var suspension = new WheelSuspension(wheelDefinition.SuspensionStiffness, wheelDefinition.SuspensionDamping, wheelDefinition.SuspensionAxis, wheelDefinition.SuspensionRest, wheelDefinition.SuspensionAttachment); // = (2000, 100, (0,-1,0), 0.5, (x,y,z))
var motor = new WheelDrivingMotor(wheelDefinition.GripFriction, wheelDefinition.MaxForwardForce, wheelDefinition.MaxBackwardForce); // (2.5, 3000, 1000)
var rollingFriction = new WheelBrake(wheelDefinition.DynamicBrakingFriction, wheelDefinition.StaticBrakingFriction, wheelDefinition.RollingFriction); // = (1, 2, 0.02)
var slidingFriction = new WheelSlidingFriction(wheelDefinition.DynamicSlideFriction, wheelDefinition.StaticSlideFriction); // = (2,3)
var physicsWheel = new Wheel(shape, suspension, motor, rollingFriction, slidingFriction);
wheels[i] = physicsWheel;
}
var bodyShape = new Box(Vector3.Zero, size.X, size.Y, size.Z, bodyDefinition.Mass); //((0,0,0), 3, 1, 5.5, 61)
bodyShape.CollisionInformation.LocalPosition = -bodyDefinition.CenterOfGravity;
this.vehicle = new Vehicle(bodyShape, wheels);
The actual forward speed from the vehicle: Vector3.Dot(LinearVelocity, WorldForward) is identical in both situations,
From the motor i get a maximal total impulse of 10.29 in the editor. (with actual speed at -0.29 and targetSpeed at 1.34, so going from backward to forward motion) While in the game it never goes above 7.3. This could explain the wheelie in the editor, but this difference looks rather small.
If i turn left/right and set the targetspeed at -10 in the editor, i can complete one circle before the centrifugal force flips the vehicle over. In the game it stays on it wheels and completes many more circles without lifting a wheel of the ground. The game vehicle even manages to register a speed of -11 while doing this while the editor vehicle goes wheels up at -7 units/s on the world forward axis. Where is this difference coming from :'(
I also don't quite understand how the wheel motor's and brakes work, if I reduce the target speed of the wheels, the vehicle happily continues driving on. So i assume it only applies force to the "wheels" when TargetSpeed < ActualSpeed? So i also have to brake when i want to slow down.
So when i brake, i notice the vehicle going into a nosedive, lifting the rear wheels of the ground, and they are still spinning freely.
So the brake force is applied between the body and the support? Which is perfectly fine of course, as long as the wheels are touching a support.
So i investigated into this, and i noticed, when i put the vehicle on it's roof and accelerate, the wheels start spinning, as is to be expected. But as soon as i return the TargetSpeed back to 0, the wheels slow down and stop. I'd assume this is due to some kind of friction, but none of the friction values i know of have influence on this (Setting Brake friction, Grip Friction or Slide Friction to 0 doesn't help).
But then i apply the brakes (IsBraking = true), and the wheels slow down at the same rate, as would be expected from the observation before, that, wheels are not affected by brakes.
I have worked with JigLibX before, and modified the most vehicle code there to simulate a motor with gearbox, but Bepu seems to be a lot more complicated to achieve this.
In jiglib, a wheel is for all purposes, a stationary object with mass of it's own and no collision response, when torque is applied to it, the wheel spins up/slows down, the difference in speed between the wheel surface and the world results in a force, that is applied to the world and the vehicle's body, and it's torque is also subtracted from the, to the wheel applied torque.
This gave me feedback on the "axle" that i used to calculate the forces on the engine.
But from what i find in bepu, the Driving Motors are only "thrusters", applying action force to the body and a reaction force to the world?
I guess i'll have to find me some time and create a vehicle from scratch with best of both worlds after i figured out why it behaves differently in these two scenarios.