?
Solved

2D car physics - make the cars spin!!

Posted on 2003-03-05
6
Medium Priority
?
2,721 Views
Last Modified: 2012-05-04
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
Comment
Question by:Keifs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Accepted Solution

by:
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

by:dclaydon
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

by:kGoo
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...
                            ang velocity = vel/radius

viola
 then you rotate the car

0
 

Expert Comment

by:ry4096
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.

sorry about that.
0
 

Expert Comment

by:CleanupPing
ID: 9464251
Keifs:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question