PDA

View Full Version : a collision of 2 balls?


Sidew
08-28-2006, 03:50 PM
I want to do the following but I have been unsuccesful:

Having 2 spheres, make an event so I can move one of them with the mouse BUT when the ball I'm moving gets closer enough to touch the other ball Alice or message would appear saying "you crashed!" or something like that meaning that you have touched the other ball.

Thx in advance!!

pausch
08-28-2006, 06:18 PM
Here's a small program that shows how to do this...

hope this helps!

Sidew
08-28-2006, 08:55 PM
Wow, thank you very much^^

Let me analize the code.
-The 2 meters it is supposed to be the distance from the centre of the ball to almost the outer part?, How did you know that(the exact distance)?

-For what is the WHILE expression (although I can suppose...)?, and the During parameter?

I have never used "While", that's why I ask. Thank you so much.
Cheers!!

EDIT: I used a "green'sBall Width instead of the "2 meters" in order to have the exact value.

Sidew
08-28-2006, 10:18 PM
Ok, I already found out.
Thank you very much!! :D :D
Any other solution is welcome.

Sidew
08-29-2006, 05:05 PM
Hi again^^, I have just more doubt.

How do I make the collision TRUE?, I mean, if the green ball gets closer enough to the red one, I want the green one not going through the red ball.
Like if the red ball was a WALL, not allowing the green one coming through.

Thanks in advance.
Cheers!! :D

EDIT:

I tried something similar to this http://www.alice.org/community/showthread.php?t=69
If anybody knows an alternative, please tell it.
See you!

pausch
08-30-2006, 02:16 PM
Just as in the real world, it's much easier to detect conflict that it is to resolve it!

Unfortunately, there's an arbitrary amount of work you'll need to do in order to achieve various levels of satisfaction in changing the behavior of objects when they physically intersect, and there's no 'easy' answer I can give you.

I suspect you're going to end up doing some calculation that runs continuously and adjusting the position of various objects, but that can be as simple as just "keeping the last known position" and reseting a ball to that location when a collision is detected. That will make the ball appear to "freeze" even though I'm still trying to move it with the mouse.

In the limit, you'd probably want the balls to collide based on their velocity and mass, and bounce off walls, etc. It would (easily) be possible to have a team of 20 people working full time on getting this problem solved "right" (there are, in fact, such companies).

So it's not a simple problem you're trying to solve...

hope this helped!