Page 1 of 1
SuspensionCarDemo2 steering doesn't work
Posted: Thu Mar 28, 2013 8:31 pm
by purple
I've got a problem with steering using SuspensionCarDemo2 example. Not sure if it has to do with the game engine or not. I also tried setting maximumTurnAngle to 1.2f and it starts with wheels being turned left.
Re: SuspensionCarDemo2 steering doesn't work
Posted: Thu Mar 28, 2013 8:37 pm
by Norbo
Are you encountering problems with the SuspensionCarDemo2 itself, or is it the usage of a car based on the demo?
The SuspensionCarDemo2 works fine for me, so if that's failing for you, I'm not sure why- perhaps update to the latest development version if you haven't already.
If it is just the usage of the car that fails, then I would recommend cross checking the usage and the demo.
Re: SuspensionCarDemo2 steering doesn't work
Posted: Thu Mar 28, 2013 8:42 pm
by purple
I copied the code from SuspensionCarDemo2 and modified it to suit my engine. Everything works fine except the steering. Is there a IRC channel for BEPUphysics maybe?
Re: SuspensionCarDemo2 steering doesn't work
Posted: Thu Mar 28, 2013 8:50 pm
by Norbo
I copied the code from SuspensionCarDemo2 and modified it to suit my engine. Everything works fine except the steering.
The constraints are built to expect a specific direction as 'forward;' my guess would be that the modified version is not entirely consistent with that expectation. If wheels want to start facing left by default, that would imply at least some of the constraints are 90 degrees off from others.
Is there a IRC channel for BEPUphysics maybe?
Nope; I prefer to keep everything on a single, public, searchable repository.
Re: SuspensionCarDemo2 steering doesn't work
Posted: Thu Mar 28, 2013 9:01 pm
by purple
Can you please point me to the right section of the code where those settings are which I would then try changing until correct behavior? Car goes forwards and backwards with no problems.
Re: SuspensionCarDemo2 steering doesn't work
Posted: Thu Mar 28, 2013 9:08 pm
by Norbo
I can't recommend trial and error in good conscience unless you're already very familiar with what all the parameters do. Constraint configuration has enough free variables involved that it can get extremely frustrating when working blindly. Also, I cannot guess with great specificity where the problem lies; I can only guess that it is somewhere in the AddDriveWheel function or perhaps in the overall car configuration (e.g. different forward directions).
Instead, I would recommend looking at those specific areas that were changed during the adaptation process. Since the original works, something about the modifications is at least related to the differing behavior.
Re: SuspensionCarDemo2 steering doesn't work
Posted: Sat Mar 30, 2013 6:59 am
by purple
Agreed, trial and error isn't smart in this case. I went through the code, mine and example's, and found out that I forgot to write two lines in the update function. Now everything works perfect.

Now how do I implement vehicle loosing grip when cornering fast?
I also made a handbrake but the vehicle never really stops. It is always moving somewhere very slowly. How do I fix this? To stop the vehicle but in a way that it still can be affected by impact of other bodies.
Code: Select all
if (Input.Keyboard.KeyPressed(Keys.Space))
{
drivingMotor1.Settings.VelocityMotor.GoalVelocity = 0;
drivingMotor2.Settings.VelocityMotor.GoalVelocity = 0;
drivingMotor1.IsActive = true;
drivingMotor2.IsActive = true;
}
Re: SuspensionCarDemo2 steering doesn't work
Posted: Sat Mar 30, 2013 4:46 pm
by Norbo
The driving motor is explicitly weakened in the configuration to more naturally accelerate:
Code: Select all
drivingMotor.Settings.VelocityMotor.Softness = .3f;
drivingMotor.Settings.MaximumForce = 100;
While you could remove this, it would cause the wheels to nearly instantly spin at full speed every time you try to accelerate.
Instead, create a separate RevoluteMotor for some of the wheels to act as the brakes:
Code: Select all
brakingMotor = new RevoluteMotor(suspensionLeg, wheel, Vector3.Right);
Space.Add(brakingMotor);
Then you can just activate and deactivate it to stop the car:
Code: Select all
if (Game.KeyboardInput.IsKeyDown(Keys.Space))
{
brakingMotor1.IsActive = true;
brakingMotor2.IsActive = true;
}
else
{
brakingMotor1.IsActive = false;
brakingMotor2.IsActive = false;
}
If you find yourself seeing some 'jiggliness' in the structure, it's because this is a rather complicated constraint-based vehicle with a lot of high stress connections. While it should be possible to tune that away, it would take time and familiarity. The SuspensionCarDemo (without a '2', the one with implicit suspension) is more stable in this regard since there are less pieces to deal with. Using the actual Vehicle will also tend to have better stability since the wheels don't actually exist.
Now how do I implement vehicle loosing grip when cornering fast?
With constraint based cars, you do not- the friction model is just the regular collision friction model. That means when the car is going fast around a corner, it will tend to slide, but you don't have any special control over it outside of the wheel material's kinetic and static friction coefficients.
The Vehicle class has a slightly more detailed friction model which is sometimes easier to tune. It still doesn't have as much detail as a racing-dedicated wheel friction model, but it is serviceable for most purposes.