Upcoming Events
5th Australasian Conference on Interactive Entertainment
12/3 - 12/5 @ Brisbane, Australia

2K Bot Prize
12/15 - 12/18 @ Perth, Australia

IEEE Symposium on Computational Intelligence and Games
12/15 - 12/18 @ Perth, Australia

IEEE Consumer Communications & Networking Conference
1/10 - 1/13 @ Las Vegas, NV

More events...


Quick Stats
4010 people currently visiting GDNet.
2240 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!



Link to us

  search:   

2D Car Physics


Introduction

Someone asked me in the #gamedev IRC channel about how to make a 2d vehicle simulator. Instead of spending all day trying to explain the concepts to him, I decided just to write this tutorial. Please bear with me, this is my first tutorial.

So as I mentioned we’re going to be learning how to make a basic 2d vehicle simulator. We’re going to do it in C# and try do use as few hacks as possible. I’ve broken the process down into three steps. First, we will learn how to setup a basic game application in C#.NET and how to draw some basic graphics (emphasis on basic.) Next, we will learn how to create a rigid body simulator using a simple Euler integrator with a variable time step. And last but not least, we will calculate vehicle forces simulating the tire patch contacting the road. And that’s all there is to it! Let’s get started.

Math Requirements

There are two ways to get through this tutorial: you can rush to the end and download the project, or you can read through it and hopefully I’ll be able to explain things clearly. If you choose the second route, you’re going to need to have a bit of math background. In a 2D simulation this is mostly in the form of a vector object. You’ll need to be able to add, subtract, dot, and project 2 vectors. Also you’ll need to be able to use a cross product. In 2D this is kind of a fake situation since we know the result will point in the screen’s direction, so the result is returned as a scalar. If you’re not familiar with any of these terms please look them up now. I tried to write this tutorial without using a matrix object but eventually I cracked and used the Drawing2D.Matrix object to transform and inversely transform a vector between spaces. If you don’t know what I’m talking about let me give you an example. Let’s say your personal body is your “local space” and the room you’re sitting in is the “world space.” Let’s also say that your monitor is the front of the world, and your eyes look in the forward direction of your local space. If you turn sideways, and transform the monitor’s direction into your space, it is now the side direction. Vise versa, if you transform your facing direction into world space, it is the opposite side direction. This is a critical concept so please, if that didn’t make sense, do some searching on Google for transforming between spaces. The reason this is so important is because we will be doing all of our vehicle force calculations in local vehicle space. Yet the vehicle itself, and its integrator, persist in world space.



Phase One

Contents
  Introduction
  Phase One
  Phase Two
  Phase Three
  Conclusion

  Source code
  Printable version
  Discuss this article