Alice Community  

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

Reply
 
Thread Tools Display Modes
Flight simulation HELP!!
Old
lstricland
Guest
 
Status:
Posts: n/a
Default Flight simulation HELP!! - 08-13-2010, 02: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
File Type: a2w Flight simulation.a2w (2.40 MB, 27 views)

Last edited by lstricland; 08-13-2010 at 03:04 PM.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 08-13-2010, 03: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
   
Reply With Quote
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Arrow 08-13-2010, 03: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.
   
Reply With Quote
I just changed it...still didn't work.
Old
lstricland
Guest
 
Status:
Posts: n/a
Default I just changed it...still didn't work. - 08-13-2010, 03: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!
   
Reply With Quote
Thanks a bunch!
Old
lstricland
Guest
 
Status:
Posts: n/a
Default Thanks a bunch! - 08-13-2010, 03:41 PM

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

Quote:
Originally Posted by debussybunny563 View Post

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.
   
Reply With Quote
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Talking 08-13-2010, 03: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 04:07 PM.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 08-13-2010, 03: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
   
Reply With Quote
Old
lstricland
Guest
 
Status:
Posts: n/a
Default 08-13-2010, 04: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 View Post
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
File Type: a2w Flight simulation.a2w (2.41 MB, 6 views)
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 08-13-2010, 04: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
   
Reply With Quote
Fixed
Old
debussybunny563
Senior Member
 
debussybunny563's Avatar
 
Status: Offline
Posts: 852
Join Date: May 2010
Arrow Fixed - 08-13-2010, 04: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
File Type: a2w Flight simulation.a2w (2.42 MB, 18 views)
   
Reply With Quote
Reply

Tags
collision, flight simulation

Thread Tools
Display Modes

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 ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.