Author |
Message |
kousha41564
|
Posted: Fri Jan 09, 2009 4:38 pm Post subject: need help with colision in a game |
|
|
alright , i got a circle dude walking around the screen, now i have no problem to detect colision against another circle, using the Pythagorean theorem
code: |
a := x2 - x1
b := y2 - y1
csq := a * a + b * b
c := sqrt (csq)
if 50 + 22 > c then
put "collide"
end if
|
. i know the other two ways are math.distance and what dot colour. i was wondering which one would be the best in my case ?
i got one person (circle) who, walks around the screen, and a couple of squares.i would like the program to be able to tell when he runs into stuff. how would this be done?
also please provide a brief explenation on how exactly this would be done?
thank you |
|
|
|
|
|
Sponsor Sponsor
|
|
|
saltpro15
|
Posted: Fri Jan 09, 2009 5:06 pm Post subject: RE:need help with colision in a game |
|
|
I would use Math.Distance, whatdotcolour is very unreliable and takes a while to hardcode |
|
|
|
|
|
kousha41564
|
Posted: Fri Jan 09, 2009 5:11 pm Post subject: RE:need help with colision in a game |
|
|
what if i have complex colours? thanks for answering |
|
|
|
|
|
The_Bean
|
Posted: Fri Jan 09, 2009 5:15 pm Post subject: Re: need help with colision in a game |
|
|
Circle -> Circle: collision detection is done by Using Math.Distance()
Colours don't matter with this method
Circle -> Square: is a bit trickier and can be done with Math.DistancePointLine()
You need to check the distance from the center of the circle to every side of the square and determine if it's less than the radius of the circle. |
|
|
|
|
|
kousha41564
|
Posted: Fri Jan 09, 2009 5:55 pm Post subject: RE:need help with colision in a game |
|
|
how long exactly would that take per vbox? since ive got a project due monday and i have to set this up for atleast 30 boxes
if it takes long i will just use the " in theory circle" thing |
|
|
|
|
|
OneOffDriveByPoster
|
Posted: Fri Jan 09, 2009 9:12 pm Post subject: Re: RE:need help with colision in a game |
|
|
kousha41564 @ Fri Jan 09, 2009 5:55 pm wrote: how long exactly would that take per vbox? since ive got a project due monday and i have to set this up for atleast 30 boxes
if it takes long i will just use the " in theory circle" thing What do you mean how long? You can write one function and call it for each box. |
|
|
|
|
|
kousha41564
|
Posted: Fri Jan 09, 2009 11:23 pm Post subject: RE:need help with colision in a game |
|
|
DUDE SERIOUSLY? where the hell have i been ? could you please please explain how taht would be done ? in the mean time i ma go read tutorials on functions. |
|
|
|
|
|
The_Bean
|
Posted: Fri Jan 09, 2009 11:44 pm Post subject: Re: need help with colision in a game |
|
|
If you mean time for you to right out the code to check each box, quite a while if you don't use arrays.
If you mean the time it takes for the program to check 1 circle against 30 boxes, on my comp it took roughly 3.5 milliseconds using my program. Which is more than fast enough. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
kousha41564
|
Posted: Fri Jan 09, 2009 11:59 pm Post subject: RE:need help with colision in a game |
|
|
ahhahaha, no i am quite sure it will take only fractions of a second, i was talking bout writing it out, thank you anyway. |
|
|
|
|
|
|