Author |
Message |
tyuo9980
|
Posted: Mon May 09, 2011 10:01 pm Post subject: Coding effective Geometry wars Pacifism collision help. |
|
|
how would i be able to make something very efficient and similar to the collision of the blue diamond pieces in the game geometry wars pacifism?
i am currently experimenting with calculating the distance between each object but it just slows down the computer too much.
video of the game:
http://www.youtube.com/watch?v=baMmw29xtEw |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
mirhagk
|
Posted: Tue May 10, 2011 7:31 am Post subject: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
The distnace between each object can actually be one of the fastest algorithms available. it's circular collision detection, which is one of the best.
If your having difficulty I'll give you a couple tips
1. The distance between two circles must be less than the radius, and how do you find the distance between 2 points?
2. Since one side of the equation needs to be square rooted (which is very costly), you could instead just square the other side (which is alot cheaper) |
|
|
|
|
![](images/spacer.gif) |
tyuo9980
|
Posted: Tue May 10, 2011 8:29 am Post subject: Re: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
mirhagk @ Tue May 10, 2011 7:31 am wrote: The distnace between each object can actually be one of the fastest algorithms available. it's circular collision detection, which is one of the best.
If your having difficulty I'll give you a couple tips
1. The distance between two circles must be less than the radius, and how do you find the distance between 2 points?
2. Since one side of the equation needs to be square rooted (which is very costly), you could instead just square the other side (which is alot cheaper)
1. using distance equation.
2. i have to use square root. you cant square a variable that you don't know the variable of.
im looking for a similar detection to the actual game. |
|
|
|
|
![](images/spacer.gif) |
mirhagk
|
Posted: Tue May 10, 2011 8:33 am Post subject: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
No you don't have to square root it. the distance equation is basically
c^2=a^2+b^2
simply equate c^2 to radius^2 and you have
if (a^2+b^2<radius^2) then
no square roots are neccassary. |
|
|
|
|
![](images/spacer.gif) |
tyuo9980
|
Posted: Tue May 10, 2011 9:21 am Post subject: Re: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
mirhagk @ Tue May 10, 2011 8:33 am wrote: No you don't have to square root it. the distance equation is basically
c^2=a^2+b^2 <---- Wont work.
simply equate c^2 to radius^2 and you have
if (a^2+b^2<radius^2) then
no square roots are neccassary.
yea ok that gives me a better understanding. thanks. i thought you had to find the distance and compare that. i didnt think about my predifined distance. |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Tue May 10, 2011 6:00 pm Post subject: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
You know that there's a predefined function for this, right?
Math.Distance (x1, y1, x2, y2) : real
You replace x1, y1 with the coordinates of one object, x2, y2 with the other and it gives you the total distance in real. |
|
|
|
|
![](images/spacer.gif) |
mirhagk
|
Posted: Tue May 10, 2011 6:52 pm Post subject: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
yeah, the distance function does square root though, which takes up more CPU time, which generally won't matter, but for tight collision detection it will for sure. |
|
|
|
|
![](images/spacer.gif) |
XZNZ
|
Posted: Sun May 15, 2011 8:48 pm Post subject: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
hey
without using sqrt function multiply by 0.5
and
x * x instead of x^2 will save a lot of time |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
HRI
|
Posted: Mon May 16, 2011 10:00 am Post subject: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
I think you mean raise it to the power of 0.5 (i.e. x^0.5 = sqrt (x)) |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon May 16, 2011 11:52 am Post subject: RE:Coding effective Geometry wars Pacifism collision help. |
|
|
floating point powers are still computationally intensive; and as mentioned above, unnecessary. Good point on x*x part -- it is sufficient to go with
code: |
if (a*a + b*b < radius*radius) then
|
If the radius of an object is constant, the radius^2 value could be stored as well. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
|