collision detection for cars
Author |
Message |
chopperdudes
|
Posted: Sun Jun 08, 2008 9:24 am Post subject: collision detection for cars |
|
|
hello. i have a friend who's making a simple "driver's ed" program, where you have 2 cars parked, and a user controlled car. the cars are in a rectangular shape, and the user controlled car is able to mimik a real car turning. how would he go about doing collision detection between 2 rectangles? he asked me to help but i can't think up of any collision detection between Math.DistancePointLine or View.WhatDotColor. both of which won't work.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Sun Jun 08, 2008 9:28 am Post subject: RE:collision detection for cars |
|
|
You need to read the collision tutorial, here.
|
|
|
|
|
|
chopperdudes
|
Posted: Sun Jun 08, 2008 10:27 am Post subject: RE:collision detection for cars |
|
|
sorry, but i don't see how i can use oval collision detection here, since all the cars are rectangular shaped. if i use oval, then the corner of the cars will not be counted for, and it will be very inaccurate.
is there any way to check if 2 rectangles overlap each other in any way?
|
|
|
|
|
|
Insectoid
|
Posted: Sun Jun 08, 2008 10:49 am Post subject: RE:collision detection for cars |
|
|
If you didn't notice, the first part of the tutorial is about rectangular collision. It uses oval examples, but from a technical point of view, it is rectangular. The principle is the same. You are checking to see if any point is inside the other rectangle.
I.E. every rectangle has 4 coordinates, x1, y1, x2, y2. Try to find exactly what the conditions must be to have a collision.
Description: |
|
Filesize: |
192.01 KB |
Viewed: |
87 Time(s) |
|
|
|
|
|
|
|
CodeMonkey2000
|
Posted: Sun Jun 08, 2008 11:36 am Post subject: RE:collision detection for cars |
|
|
Wait, the cars rotate? If they do, you need to know all four corners, and look at richcash's tutorial. I think the one you want is convex polygon vs convex polygon. Or mabey line segment vs line segment. Just look at all of them anyway
This is his tutorial:
http://compsci.ca/v3/viewtopic.php?t=13661&postdays=0&postorder=asc&start=15
|
|
|
|
|
|
jackjixing
|
Posted: Sun Jun 08, 2008 11:45 am Post subject: Re: collision detection for cars |
|
|
hi, Chopperdude is asking the quesiton for me. the car is rotating. so when you draw the dots and the lines, they have to move along with the car. how do you make that happen? can some one help? thank you.
|
|
|
|
|
|
CodeMonkey2000
|
Posted: Sun Jun 08, 2008 5:00 pm Post subject: RE:collision detection for cars |
|
|
For that you need to use a little trig. Pick and angle and a speed for the car. Figure out the speed in the x direction and in the y direction, and add this to all you verticies. You do this for each point.
This concept of rotation has been asked so often, we might need to make a tutorial on it similar to Mazer's jump tutorial :S
|
|
|
|
|
|
jackjixing
|
Posted: Sun Jun 08, 2008 11:22 pm Post subject: Re: collision detection for cars |
|
|
i think i get the idea, but coding it would take a while. thanks a lot. would definitely encourage someone to make a tutorial. thanks
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|