Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
bouncing balls
Author Message
this_guy

Posted: Sun Jul 25, 2004 3:53 pm   Post subject: bouncing balls

i've been trying to get two balls to bounce off each other

i tried using math.distnc to c whether 2 balls r touching, den hav dem change directions but dat didnt look real

Paul

Posted: Sun Jul 25, 2004 4:21 pm   Post subject: (No subject)

http://www.compsci.ca/v2/viewtopic.php?t=5246
Cervantes

Posted: Mon Jul 26, 2004 6:49 am   Post subject: (No subject)

note that my approach to circular collision does not work very well for top down views, though it is excellent for a side view, like slime-volleyball.
for top-down, try thoughtful's approach:

Posted: Mon Jul 26, 2004 6:35 pm   Post subject: (No subject)

or as done in many programs, create a cute, simple collision detection.
Create a square with slightly smaller parameters than the circle, and make its center the same as the circles. If one of the immediate sides, or edges, or even the middle hits the other circle, write a procedure that checks which general direction (top_right,top_left,bottom_right,bottom_middle,etc. etc.) the opposing circle hits, and change the opposing balls direction to the opposite direction of its original direction, and maybe change its speed a bit. Lol, cheap, but it works.
this_guy

Posted: Tue Jul 27, 2004 3:06 pm   Post subject: (No subject)

wow thnx guys...except for danshadow...didnt get wut u said

1 problem, i looked at cervantes, but sometimes 2 balls would get stuck together and rotate around each other.

that happened with smthg i tried 2, but dunno wut da prob is
Cervantes

Posted: Fri Jul 30, 2004 6:42 am   Post subject: (No subject)

 code: % moves the balls forward 2 steps so they dont get stuck with each other as often                         x (i) += dx (i)                         y (i) += dy (i)                         x (k) += dx (k)                         y (k) += dy (k)

That is the part that tries to prevent the balls from sticking together. If you find that they are sticking together, do it again.
 code: % moves the balls forward 2 steps so they dont get stuck with each other as often                         x (i) += (2 * dx (i))                         y (i) += (2 * dy (i))                         x (k) += (2 * dx (k))                         y (k) += (2 * dy (k))

Posted: Fri Jul 30, 2004 8:55 pm   Post subject: (No subject)

This is an example of what I meant.(the picture attached)
[Open the file for this example]
See the light blue square behind the circle? That is the offset for the radius
in each corner. Now if a part of the second square around the second circle enters inside the first square of the first circle, it initiates a "collision" procedure which repels the second circle (and/or the first) in the opposite direction. If this clears up what I mean, my intention is fufilled.

ballex.bmp
Description:
 Ball Collision Example
Filesize:  414.06 KB
Viewed:  4783 Time(s)

this_guy

Posted: Tue Aug 03, 2004 4:02 pm   Post subject: (No subject)

oh! i c...

kinda cheap, and fake

especially if u hav a lot of diff circles.

but its so much easier:D

Posted: Tue Aug 03, 2004 6:57 pm   Post subject: (No subject)

hehe, true, true. But a lot of people seem to use that! Its kind of weird, but if so many people do it, why not?
Delta

Posted: Thu Aug 05, 2004 11:36 am   Post subject: (No subject)

Because it's inefficient... use cervantes method which is about a hundred times better... I like how you have the engery transfer goin' on there cervantes real smooth use of physics lol... but ya... will balls... don't use a box for collisions... it's common sense...

Posted: Thu Aug 05, 2004 3:42 pm   Post subject: (No subject)

Im not saying you SHOULD use box collision detection, im just saying that quite a few people use it, and its easier if you dont understand physics.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 11 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: