• Home
  • Products
    • Game Engine
      • Base
      • Mathematics
      • Geometry
      • Physics
      • Particles
      • Animation
      • Graphics
      • Game
      • Game UI
    • Windows Forms
      • Docking Windows
      • Text Editor Control
  • Downloads
  • Buy
    • Overview
    • Professional
    • Indie
    • Non-Commercial
  • Support
    • Overview
    • Blog
    • Forum
    • License FAQ
    • Documentation
  • About
    • About Us
      • Services
    • Contact Us
    • Press
    • Legal Terms
      • Imprint (English)
      • Imprint (German)
Select the search type
 
  • Site
  • Web
Search
DigitalRune.com
Login |Register
NEWS News RSS Feed BLOG Blog RSS Feed FORUM News RSS Feed DOCUMENTATION DigitalRune Software on YouTube DigitalRune Software on Twitter
You are here: SupportForum

If you want to contribute to the forum discussions, please Register or Login.

SearchHome
  • 1
  • 2
  • 3
  • 4
  • 5
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineCar Physics questionsCar Physics questions
Previous
 
Next
New Post
4/12/2011 10:38 AM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Car Physics questions 
Juan Alberto wrote:
When you say "let the simulation run parallel to the Draw() method" you mean that by default the car simulation is not multithreaded?

 
In MyGame Simulation.Update() is called in MyGame.Update(), like this:

    protected override void Update(GameTime gameTime)
    {
      ...

      // Advance physics simulation.
      Simulation.Update(elapsedTime);

      // Update game components.
      base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
      ...
    }

Simulation.Update() is internally multithreaded by default. But in XNA MyGame.Update() and MyGame.Draw() are executed sequentially. That means, if Simulation.Update() takes 16ms and Draw() takes 11ms, then one frame takes >27 ms.
I have made following changes to MyGame.cs:

    private Task simulationTask;
    
    protected override void Update(GameTime gameTime)
    {
      simulationTask.Wait();

      ... 
      
      base.Update(gameTime);

      simulationTask = Parallel.Start(() => Simulation.Update(elapsedTime));
    }
 
    protected override void Draw(GameTime gameTime)
    {
      ...
    }

Now, Simulation.Update() starts at the end of Update(), runs parallel to Draw() and ends at the beginning of the next Update(). In this case we get a frame time of nearly 16ms (+ the time of the base.Update() + overhead) because physics and graphics run in parallel.
One important thing is that the Draw() code must not access the rigid body data (e.g. RigidBody.Pose) directly because it is modified in parallel. Therefore, the game components must read and store the RigidBody.Pose in their Update() method and use only the stored values in their Draw() method.
This is one method to make the game more parallel.

 
New Post
5/11/2011 6:16 PM
 
Juan Alberto
No Ranking

Joined: 3/2/2011
Posts: 59
Re: Car Physics questions 
Hi, I got some new questions :)

I've run into some trouble when changing the parameters of the wheels to adjust it to my assets. Basically, the Radius of the wheel seems to have a dependency on the SuspensionRestLength so that for certain values the car will start to behave erratically or simply not move at all. By trial and error I've come to the conclusion that SuspensionRestLength must be greater than Radius * 1.5, or else problems will occur. Does that make sense?

Also, quoting the docs, "The ray is attached to the car where the suspension is fixed". But where is the suspension fixed? Is it at the center of the wheel minus SuspensionRestLength vertically? Does that point need to be inside the chassis? My car has the wheels outside the chassis (like an F1 car), not underneath. Can that cause any problems?

Thanks
 
New Post
5/11/2011 8:15 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Car Physics questions 
Hi,
the point where the suspension is fixed is defined using Wheel.Offset (relative to the Chassis). From there move the suspension length down and you arrive at the wheel center.

Using Wheel.Offset you can place the wheel outside of the chassis shape - no problem.

In the current version, the effective suspension length is limited by the wheel radius. For example, if the wheel radius is 40 cm and the suspension length is 60 cm, the supension can be compressed by max. 20 cm. If the wheel radius is changed to 50 cm, the suspension can be compressed by max. 10 cm and you have to set a higher suspension stiffness to get the same max. suspension force.

The reason to limit the effective suspension length by the wheel radius is: the wheel upwards motion should be limited, so that the wheel does not penetrate the chassis. - This is not so useful if the wheels are outside the car. You can try to change this in the source code. In Wheel.cs change line 527 from
    SuspensionLength = Math.Max(hitDistance - Radius, Radius);
to 
    SuspensionLength = hitDistance - Radius;
If you change this line, the suspension length can be compressed up to 0 and even get negative. I haven't tested this, but this could give better results with different wheel sizes and wheels outside the car.

Conclusion: If wheel radius increases, you can
a) adapt the stiffness parameter, or
b) increase the SuspenionRestLength too, or
c) change the code in Wheel.cs to remove the suspension length limitation.

Hope this helps.
 
New Post
9/30/2011 12:38 PM
 
Juan Alberto
No Ranking

Joined: 3/2/2011
Posts: 59
Re: Car Physics questions 

Hi again. Two questions today:

1) I'm trying to implement a handbrake feature for the raycast car so that it does not slide down steep hills. Setting each wheel's BrakeForce and RollingFrictionForce to very large values does not completely stop the car from slowly sliding down. Is that possible somehow?

2) When the car is running over bumpy terrain, often after a high jump it lands with the front wheels first, and if they are not facing straight the car will "lose the rear end" and oversteer heavily, which is probably realistic but quite annoying in a game. Is there any measure that could minimize that, such as detecting which wheels have a high SkidEnergy and applying brakes to them for instance? (kind of simulating what Traction Control does in real cars)

Thanks!

 
New Post
10/1/2011 11:53 AM
 
MartinG
7th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 446
Re: Car Physics questions 
Ok, this probably takes some time to figure out. We will take a look at these two issues next week.
 
New Post
10/4/2011 4:33 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Car Physics questions 

1) Things that are slowly sliding down an inclined plane are typical (and annoying) errors of physics simulations. We can try to completely remove all errors in the simulation- which is very hard. But since this is a game and we can use any trick that is not visible to the user.
Try the following:
Remember the vehicle.Chassis.Pose in each frame. And in each frame, f the car was braking and the current vehicle.Chassis.LinearVelocity and AngularVelocity are very low, then simply set the current vehicle.Chassis.Pose to the pose of the old frame. (The velocity limits must be determined experimentally.)
Does this work in your case?

I will check if I find anything in the simulation code that could remove the sliding more elegantly.

2) If the car loses the rear end, that means the front wheels have more traction than the rear wheels. Try to increase the friction (Wheel.Friction) of the rear wheels until traction of front and rear wheels are balanced.

You can also try a dynamically adapting friction (by modifying the VehicleForceEffect code):
If the wheel should not slide, use a higher friction. If the wheel should slide (e.g. because the handbrake is active), use a lower friction.

Other options:
- If the wheel is skidding (SkidEnergy > 0), reduce the motor force or brake force on this wheel.
- Add artificial counter-forces that stabilize the car or create the car dynamics that are needed in your type of game.

I hope this helps.

 
New Post
10/7/2011 5:49 PM
 
Sweenie
No Ranking

Joined: 9/16/2011
Posts: 9
Re: Car Physics questions 

Regarding issue 2.

If the car becomes airborne and land on the front wheels while they are turned that will compress the suspension quite a bit in the front and thus
generate alot of friction force and if the back wheels are not touching the ground the car can easily do a "pirouette".

I had the same problem in my own raycast implementation and solved that by limiting how much friction force the tire could generate.
for example...
maxNormalForce = suspensionStiffness * vehicleMass * 0.3f;
lateralFriction = Min(maxNormalForce, normalForce) * wheelSlip;

 
New Post
10/7/2011 7:46 PM
 
HelmutG
6th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 565
Re: Car Physics questions 
That is a good tip. In DigitalRune Physics there is a Wheel.MaxSuspensionForce property that acts like the maxNormalForce parameter.
 
New Post
12/17/2011 5:16 PM
 
Juan Alberto
No Ranking

Joined: 3/2/2011
Posts: 59
Re: Car Physics questions 

Right, a long time and much experimentation later, I settled for the following combination of solutions:

A) Reducing MotorForce on skidding wheels (traction control)

B) Applying a Torque that counter-acts high angular velocities on the Yaw axis (in fact angular damping but only on one axis). This was right in front of my face but didn't think of it until a few days ago, and it was the key.

This makes the car nicely stable on bumpy terrains and prevents most "pirouettes" when landing (or at least makes them more controllable).

So, thanks for all suggestions, and apologies for the delay in replying, I got carried away doing other stuff.

 
New Post
12/19/2011 8:26 AM
 
MartinG
7th Level Poster

www.digitalrune.com
Joined: 10/15/2006
Posts: 446
Re: Car Physics questions 
Thanks for the follow-up. Can't wait to see it in action! :-)
 
 Page 2 of 3
Previous123Next 
Previous
 
Next
HomeHomeDigitalRune Sof...DigitalRune Sof...Game EngineGame EngineCar Physics questionsCar Physics questions


DigitalRune is a trademark of Garstenauer Information Technology OG.

Garstenauer Information Technology OG
Weingartenstrasse 35, 4452 Ternberg
Austria (EUROPE)
office@digitalrune.com

Home Products Downloads Buy Support About Us
Game Engine Particles Windows Forms Professional Blog Services
Base Animation Docking Windows Indie Forum Contact Us
Mathematics Graphics Text Editor Control Non-Commercial License FAQ Press (News)
Geometry Game Documentation Legal Terms
Physics Game UI Imprint
Impressum
Copyright © 2006-2012 Garstenauer Information Technology OG Terms Of UsePrivacy Statement