Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
alice object question
Old
Chaosbubba
Guest
 
Status:
Posts: n/a
Default alice object question - 03-29-2008, 02:34 PM

Aight im a little confused :P im doing a project for my class to create a "put put game" using alice. im doing pretty good on it untill i got to a part where i need to make an object move once the "ball" gets close to it. I can make the object move or preform and action only when the ball stops at the object. Just to give you a little more info, i am making a tennis ball (used as golf ball) run into a tennis racket and the tennis racket spin and shoot the ball off in a random direction. Unfortunately i can only get the tennis racket to spin and shoot the ball off in a random direction if the ball stops near the racket. I need the tennnis racket to spin and shoot the ball off even if the ball is moving through it and it would be even more amazing if i could get the ball to stop when it hits the racket then shoot it off.
   
Reply With Quote
Old
lanceA
Guest
 
Status:
Posts: n/a
Default 03-29-2008, 04:52 PM

Spelling and sentence structure are often prerequists for college. You might wish to practice these skills.

You have stated your problem in a somewhat very generic manner. What specifically are you having problems with?

If I am understanding your problem it appears that you first need to create a collision() method to determine if the tennis ball has met the tennis racquet. Once this function returns true then you need a method that accepts this returned value and deals with it appropriately.

For example, you could have a method, ballMeetsRacquet() which simply uses the world function, random number, and then based upon the number returned, calls the ball's move method to cause the ball to move in the appropriate direction based upon the value returned by the random number function.

Good luck,
   
Reply With Quote
Old
Chaosbubba
Guest
 
Status:
Posts: n/a
Default 03-29-2008, 05:12 PM

Collision method? That would require that the ball actually stop upon hitting the racket wouldn't it? At the present, the ball just goes straight through the racket.
   
Reply With Quote
Old
Moonsword
Guest
 
Status:
Posts: n/a
Default 03-29-2008, 10:29 PM

I suspect that Chaosbubba and I are in the same class, and in any case, I seem to be running across much the same problem.

The problem here is setting up the method itself. Either the 'distance to' function needs to be kept out of an If/Else statement's conditional, or it's measuring from the origin of an object to the origin of another object, not the 'outside' of the mesh to the outside of the mesh, which is how a human would measure distance. Essentially, we're both having trouble getting Alice to detect that a collision has occurred between two objects. Any advice on how to set that up?
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 03-29-2008, 11:10 PM

Quote:
Originally Posted by Moonsword View Post
I suspect that Chaosbubba and I are in the same class, and in any case, I seem to be running across much the same problem.

The problem here is setting up the method itself. Either the 'distance to' function needs to be kept out of an If/Else statement's conditional, or it's measuring from the origin of an object to the origin of another object, not the 'outside' of the mesh to the outside of the mesh, which is how a human would measure distance. Essentially, we're both having trouble getting Alice to detect that a collision has occurred between two objects. Any advice on how to set that up?
If you will go to Google and search for the following keywords:

collision site:www.alice.org

you will find about 250 postings on collision detection. This is probably the most often discussed topic on the Alice 2.0 forum.

Good luck in solving your problem.
Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm
   
Reply With Quote
Old
Moonsword
Guest
 
Status:
Posts: n/a
Default 03-30-2008, 12:12 AM

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.

Last edited by Moonsword; 03-30-2008 at 12:35 AM. Reason: Further research, and then bitter experience
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 03-30-2008, 07:33 PM

Quote:
Originally Posted by Moonsword View Post
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
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 03-31-2008, 10:37 AM

Quote:
Originally Posted by DickBaldwin View Post
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.
See the attached.

The mad scientist walks only when the world level variable Walk is true. Walk in turn is toggled by the spacebar with an “event when.”

Note it is important not to use an “event while” here – in the current version of Alice, that gets evaluated independent of the loop and can leave the loop index in an undefined state (and crash the program).

As shown, the while is evalated inside the loop and the method called executes in a fixed time, so the problem doesn’t occur.

(Note: I just used the canned method for the walk, however you can also use "move at speed" inside the while if you want to control the objects direction, etc. in addition to a simple start/stop. That will just keep an object moving forward - change directions by turning it.)
Attached Files
File Type: a2w Mad Scientist.a2w (725.4 KB, 127 views)

Last edited by DrJim; 03-31-2008 at 10:40 AM.
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 03-31-2008, 11:20 AM

Quote:
Originally Posted by DrJim View Post
See the attached.

The mad scientist walks only when the world level variable Walk is true. Walk in turn is toggled by the spacebar with an “event when.”

Note it is important not to use an “event while” here – in the current version of Alice, that gets evaluated independent of the loop and can leave the loop index in an undefined state (and crash the program).

As shown, the while is evalated inside the loop and the method called executes in a fixed time, so the problem doesn’t occur.

(Note: I just used the canned method for the walk, however you can also use "move at speed" inside the while if you want to control the objects direction, etc. in addition to a simple start/stop. That will just keep an object moving forward - change directions by turning it.)
Thanks for the reply. I could probably use your approach and figure this out on my own, but let me simply ask you since you probably already know the answer.

Assume that I have two spheres separated by 10 meters. I execute a single move command on each sphere causing it to move directly toward the other sphere with a specified movement distance for each sphere of 20 meters and a specified duration of five seconds for each sphere. Given this code alone, the two spheres will pass right through one another at approximately 2.5 seconds and will end up separated by 10 meters, but they will have swapped positions.

Is there a way to write and execute code that will monitor the distance between the centers of the two spheres and cause both of them to stop without human intervention when the distance between them is less than one meter? In that case, their centers will end up separated by slightly less than one meter in a little less than 2.5 seconds and neither sphere will have completed its trip of 20 meters originally specified by the two move commands.

If so, is there any requirement to do any cleanup as a result of neither the overall distance specifications nor the overall time specifications having been satisfied?

Thanks,
Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 03-31-2008, 03:57 PM

Hey, I’m retired. Don’t you have a class or a TA that you can assign this kind of stuff (noticed that was a requirement for being a Beta tester for 3.0)?

Think the attached isn’t exactly what you asked for but does generally what you wanted – didn’t work out detailed times or distances or add the logic for the “miss” case. The only thing I know that has to be reset is the subsequent poistions of the spheres.

Also had a bit of a trouble with drag and drop for the test. Ended up first defining a Boolean variable and then draging its argument into the while and deleting the variable itself – not an unusual thing to have to do in Alice.
Attached Files
File Type: a2w Spheres.a2w (190.2 KB, 120 views)
   
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.