Alice Community Flight simulation HELP!!
 User Name Remember Me? Password

 Thread Tools Display Modes
 Flight simulation HELP!!
lstricland
Guest

Status:
Posts: n/a
Flight simulation HELP!! - 08-13-2010, 03:24 PM

I'm working on a flight simulation project where the plane will crash on the ground when it hits or contacts the barn house of the windmill. I've tried to follow the other codes from other flight simulations on here, but I couldn't make the plane to crash. I'm attaching the file on here. I've been working on this for two days now and I'm a little "punched-drunk".

When I try to put an If/Else statement:

If [plane] distance above [ground] < 0
call world.collision method
Else
Do nothing

The world.collision method works. However, since I have my plane flying in a loop with the engine sound, even after the crash, the sound still keeps going.

So, I thought that since this has worked with the "ground", I thought it would work on the barn and the windmill as well. Well, it didn't. I changed the "If/else" statement to:

If [plane] distance to [barn] < 0

The plane just went past through the building.

Here are my questions:

- What did I do wrong when I changed the "If/else" statement? How come it worked when the target was the ground and not the barn or the windmill?

- How can I make the infinite loop (where I have the code for the engine sound and plane flying) stop after the crash?

I would appreciate any help. Thank you!

thank you!!
Attached Files
 Flight simulation.a2w (2.40 MB, 28 views)

Last edited by lstricland; 08-13-2010 at 04:04 PM.

 Dameria Senior Member     Status: Offline Posts: 976 Join Date: Sep 2009 Location: United States 08-13-2010, 04:20 PM The reason it goes right through the barn is because you made it "Distance to < 0". Think about it logically now, when will the planes distance to the barn every be a negative number? It is literally impossible. When you are even an inch away from the barn, the distance to the barn will still be 1 inch. Even if you managed to fly perfectly into the barn, crossing the axis of the plane with the axis of the barn, the distance to the barn will still be 0, and when you pass by it, the distance will just go back up again but not into the negatives, your collision method will only work when the distance is less than 0, so it is impossible. What you need to do is the function "object is within distance of object" for the barn, so that when the plane is within a certain distance of the barn, it will crash. Check out my best projects so far and please comment: Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548 Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408 Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725 Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
debussybunny563
Senior Member

Status: Offline
Posts: 852
Join Date: May 2010
08-13-2010, 04:31 PM

Quote:
 How can I make the infinite loop (where I have the code for the engine sound and plane flying) stop after the crash?
Make a boolean variable called 'crash.'
In your collision method,
Quote:
 If [plane] distance above [ground] < 0 call world.collision method Else Do nothing
Add 'crash set value to true' in the 'if' part as well.
Basically,

If [plane] distance above [ground] < 0
[crash] set value to [true]
world.collision method

Else
Do nothing

Next, get rid of the infinite loop.
Instead, use a while with the [crash] is [true] inside, with your flying method inside the while statement.

So,

While [crash] is [true]
world.flyandsound

When [crash] becomes true, then you won't hear the sound nor be able to fly.

 I just changed it...still didn't work.
 lstricland Guest   Status: Posts: n/a I just changed it...still didn't work. - 08-13-2010, 04:38 PM Thank you for the quick response. This project is due midnight on Sunday and I still have other worlds to finish. This is the one that's really giving me a hard time. I've changed the If statement to "plane is within 1 meter of barn", but the collision method was not executed. I tried to do the "plane distance above ground < 0", it executed the collision method. I'm not really sure what to do. Also, even with the collision to the ground, the engine sound is still playing and the airplane continues to "fly" under ground??? Thank you again!
 Thanks a bunch!
lstricland
Guest

Status:
Posts: n/a
Thanks a bunch! - 08-13-2010, 04:41 PM

Thank you so much...I'll go ahead and try this one. I'll be back (hehe!).

Quote:
 Originally Posted by debussybunny563 Make a boolean variable called 'crash.' In your collision method, Add 'crash set value to true' in the 'if' part as well. Basically, If [plane] distance above [ground] < 0 [crash] set value to [true] world.collision method Else Do nothing Next, get rid of the infinite loop. Instead, use a while with the [crash] is [true] inside, with your flying method inside the while statement. So, While [crash] is [true] world.flyandsound When [crash] becomes true, then you won't hear the sound nor be able to fly.

 debussybunny563 Senior Member     Status: Offline Posts: 852 Join Date: May 2010 08-13-2010, 04:44 PM Let us know if you have problems with that. BTW, if you could post the world (when you post, click 'manage attachments,' and upload your file), I could try to fix it. EDIT: Oops, didn't see that you had posted it. I'll take a look at it. Good luck! Last edited by debussybunny563; 08-13-2010 at 05:07 PM.
 Dameria Senior Member     Status: Offline Posts: 976 Join Date: Sep 2009 Location: United States 08-13-2010, 04:56 PM Just telling you now, a While statement is basically the same exact thing as a loop, it just tells the loop when the stop. Because the crash is only going to happen once per flight however, it is a good idea to use the While statement, but you can do the same thing with a loop if you know how. Also the boolean is a good idea. You can use that to stop the sounds once the plane crashes by putting the sounds out of an infinite loop and into a while statement as well. Check out my best projects so far and please comment: Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548 Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408 Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725 Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
lstricland
Guest

Status:
Posts: n/a
08-13-2010, 05:33 PM

I just tried to put it in a "While" loop, but it still didn't crash on the barn?

I actually need to make it crash to the barn or the windmill, not to the ground. I am attaching the updated version of the Alice file that I'm working on.

I appreciate any help you can give me. Thank you so much!

Quote:
 Originally Posted by debussybunny563 Let us know if you have problems with that. BTW, if you could post the world (when you post, click 'manage attachments,' and upload your file), I could try to fix it. EDIT: Oops, didn't see that you had posted it. I'll take a look at it. Good luck!
Attached Files
 Flight simulation.a2w (2.41 MB, 7 views)

 Dameria Senior Member     Status: Offline Posts: 976 Join Date: Sep 2009 Location: United States 08-13-2010, 05:45 PM Maybe you have the radius of the barn wrong. I saw you said before that you did < 1 meter? The barn is probably more than 1 meter radius, try larger numbers until you get a result that you like. Check out my best projects so far and please comment: Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548 Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408 Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725 Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
 Fixed
debussybunny563
Senior Member

Status: Offline
Posts: 852
Join Date: May 2010
Fixed - 08-13-2010, 05:55 PM

I edited your first version.

In your events, you didn't have the collision method implemented, so I added it to the events list, as well as the while statements and boolean variable.

Take a look:
Attached Files
 Flight simulation.a2w (2.42 MB, 18 views)

 Tags collision, flight simulation

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge