Solved

# 2D car physics - make the cars spin!!

Posted on 2003-03-05
Medium Priority
2,733 Views
I'm looking for help on a 3D racing car game that I'm doing for my final year project. I'm sticking to 2D physics by ignoring the y-component for now. Given I have the vehicles centre of mass/gravity, velocity, angular_velocity, acceleration, angualar_acceleration abd the intersection point I want to know how to present realistic collision detection.

I have studied the chris  hecker articles http://www.d6.com/users/checker/ but cannot figure out how you determine the collision normal. Also I am not familiar with C++ and so cannot seem to applay the 2Dsample code included to my vehicles. I'm using DirectX and C with OBBs for collision detection while the physics is pulled from the Car Physics for games website http://home.planet.nl/~monstrous/tutcar.html.

I would really appreciate help in this area. I have been working on it for weeks but physics is not my forte and my project deadline is fast approaching.... 75 points and my sincere gratitude are up for grabs - thanks!!!
0
Question by:Keifs

Accepted Solution

ry4096 earned 300 total points
ID: 8077360
Hello,
I've been thinking about this topic a lot, also. I think I have a solution, but I'm still not sure how to express it in source code. Anyway, this is my idea for collision detection:

To calculate whether or not a collision has happened, you need to use Linear Geometry. Let's say you wanted to know if polygon A had collided with polygon B. If there was a collision, then one of the vertices would end up sticking into polygon B (picture a triangle hitting a side of a square). So, you just need to find out if a vertex of polygon A is inside polygon B. To do this, you need to use the coordinates of each vertex of polygon A in the linear equations of polygon B
([y < mx + b] or [y < mx + b] depending on the line's location). If one of the vertexes returns "true" on all of the linear equations, then you have a collision.

For calculating the spin created by a collision, I figured that if you gave each vertex a mass and varibles for velocity, then it should work. Just treat each vertex as an object (obey the laws of basic physics) and use the lines to hold them together. I'm uncertain about whether this will work or not because I haven't gotten the chance to test it yet, but I have a feeling it will.

It's really hard to explain these things without a diagram, so feel free to reply if you have any questions. Good luck on your project.
0

LVL 1

Expert Comment

ID: 8207515
I think you mean the z access (vertical component) - x & y are the flat plane components.

Have a read of the O'Reilly published book - "Physics for game programmers".

This covers the physics for most games and includes sample code for the different algorithms.

DC
0

Expert Comment

ID: 9127621
Well, what Id do is such:

- make a function that calculates the distance btw the 2 centers of gravity... (pyth. thm)
- make each car have a velocity vector and a position vector

(i.e.

D3DVECTOR vel, pos;

vel.x = ...
vel.y = ...
vel.z = ...
.
.
.

)

Then, Id calculate the magnitue of the velocity vector that is perpendicular to the car thats being hit (doesnt really matter which one, just pick),
and using some other numbers (ie accel, mass, etc) calculate the torque about the center of gravity...
then, knowing
then velocity perpendicular to the original (car being hit) vector, and the radius r where the vectors intersect, you know the angular velocity...

viola
then you rotate the car

0

Expert Comment

ID: 9165340
yeah, what  kgoo said is better.

I tried to use what I said up there in a test program and it was really unstable. The object kept on flying through it self and acting jelo-like. It's definetly not what you're looking for.

0

Expert Comment

ID: 9464251
Keifs:
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
###### Suggested Courses
Course of the Month7 days, 4 hours left to enroll