Quote:
Originally Posted by Moonsword
EDIT: Never mind. I managed to find something after refining the search queries. Apparently, the if/else was fudging things. >.>
EDIT 2: For the record, Alice measures the distance between objects from the origin of said objects' bounding box, not edge of mesh to edge of mesh. Knowing this makes it much easier to understand why "collision detection" doesn't seem to work even when the code is right.
|
I haven't given collision detection in Alice a lot of thought and I may be completely wrong on this, but I believe that the collision detection issue is much more significant than simply how the distance between two objects is measured.
One of the great things about Alice 2.0 is that
you can cause objects to perform long smooth motions with a single statement.
One of the bad things about Alice 2.0 is that
you can cause objects to perform long smooth motions with a single statement.
Consider a baseball batting practice scenario. Assume that there is a pitching machine on the pitcher's mound and the distance from the machine to the backstop is known. A single statement can be used to cause the baseball to move from the mound to the backstop. A second statement could be used to cause it to drop to the ground when it reaches the end of its trip and hits the backstop.
Now consider what happens if the batter manages to put the bat in front of the baseball. Too bad, the baseball will go right through the bat. As far as I know, no amount of computation involving the distance of the ball from the bat will prevent the ball from completing its journey once that journey begins.
Therefore, when there is a need to detect a collision between two objects, it is necessary to use a series of short motions (probably in a
while or
for loop) instead of a single motion. That's OK, we do that all the time in other programming languages. However, Alice gets very grumpy when you force her to execute hundreds and possibly thousands of statements in a short period of time. The smaller you make the incremental motion, the more precise you can be in making the distance measurement necessary to detect a collision between the ball and the bat. Unfortunately, decreasing the length of the incremental motion also increases the computational load on Alice.
As an example of what can happen when you are forced to chop a large motion into a series of very small motions in Alice, see the trajectory programs at
http://www.dickbaldwin.com/alice/Alice0930.htm
One program uses the equations of motion to make very small incremental movements of a projectile in order to produce a reasonably accurate representation of the trajectory of a projectile. That program doesn't run very smoothly on my machine, but granted, my machine isn't particularly fast.
Another program at that same site approximates the trajectory using a circular arc that is implemented with a single statement. While that program is not true to the equations of motion, it runs very smoothly on my machine. The conclusion is that we need to take advantage of the built-in motion capabilities of Alice whenever possible, but those built-in motion capabilities are generally incompatible with collision detection.
I would really like to be proven wrong on this. If anyone knows how to interrupt the movement of an Alice object after it has begun, I would like to hear how to do it.
Dick Baldwin
Free Alice tutorials:
http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials:
http://www.dickbaldwin.com/toc.htm