Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 collision detection for cars
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chopperdudes




PostPosted: 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
Sponsor
sponsor
Insectoid




PostPosted: Sun Jun 08, 2008 9:28 am   Post subject: RE:collision detection for cars

You need to read the collision tutorial, here.
chopperdudes




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




PostPosted: 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.



sample.bmp
 Description:
Box Co-ordinates
 Filesize:  192.01 KB
 Viewed:  87 Time(s)

sample.bmp


CodeMonkey2000




PostPosted: 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 Razz

This is his tutorial:
http://compsci.ca/v3/viewtopic.php?t=13661&postdays=0&postorder=asc&start=15
jackjixing




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




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




PostPosted: 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
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: