• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Circle to Circle Collisions?

Amon

Member
Joined
Nov 19, 2018
Messages
88
How would I go about making Circle to Circle collisions in CX?
 
Look into fantomCX, there is a bunch of collision methods in one module. Sorry not at my comp. Let me know if you find it.
 
Did you found it? Here is one that just relies on the parameters:

Cerberus:
'-----------------------------------------------------------------------------
Function Coll_Circle2Circle:Bool(x1:Float, y1:Float, radius1:float, x2:Float, y2:Float, radius2:float)
    Local xf:Float
    Local yf:Float
    Local rf:Float
   
    xf = x1 - x2
    xf *= xf
    yf = y1 - y2
    yf *= yf
    rf = radius1 + radius2
    rf *= rf
    If (xf+yf) < rf Then Return True
    Return False
End
 
You read my mind, Mike. I was just going to request this but you've don it already. lol

Thanks, Mike.
 
Circle-circle is easy: just get the distance between the center of both circles (using Pythagora's Theorem) and see if it's equal or smaller then the sum of the radius (radi?) of both spheres.

Once you know/understand that, you can write that function above with your eyes closed ;)
 
Circle-circle is easy: just get the distance between the center of both circles (using Pythagora's Theorem) and see if it's equal or smaller then the sum of the radius (radi?) of both spheres.

Once you know/understand that, you can write that function above with your eyes closed ;)


You don't need to take the square root, though, unless you want the actual distance. Comparing the squared distances is enough to test for a collision, and if your objects are mostly the same size or of a fixed size you can have the square of the sum of radii as a known value or a constant.

(Not so much a problem these days, but there was a time when sqrt() was expensive...)
 
You don't need to take the square root
I know, it's a common optimization for that - the other one being xdiff = x2-x1; xdiff*=xdiff to avoid pow(2) ;)

If you want the ultimate speed, you can use the radii to build squares and do an AABB collision first, which doesn't involve any multiplication - and only test if the circles collide if the rects are colliding first ;)

Or you can even go crazy and do a quadtree on screen and test only the objects in the same quadrant as the player ^_^
(Those two of course are only necessary if you have tons of objects and collisions going on!)
 
Yeah, I always do the multiply, can't bring myself not to. I try to train myself not to care about speed when it doesn't matter, but sometimes leaving out the obvious optimisation seems unbearable. Even in the GUI...
 
I do it too! Sometimes I'm even worse, because my first computer, an MSX, had a Z80 as CPU, which doesn't have multiplication or division opcodes. So, whenever its possible you'll see me using bit shifting to multiply or divide ;)

BAD dinossaur, bad!! :D
 
Back
Top Bottom