Alice Community  

Go Back   Alice Community > Alice 2 > Works-In-Progress

Reply
 
Thread Tools Display Modes
Collision Detection!
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default Collision Detection! - 12-01-2009, 04:01 PM

I have been hearing a lot about collision detection and how it is so hard in Alice to make, so I decided to give it a try, and so far I think I have one part down really well in this program.

You move with arrow keys, and for now, if you try to move through the blue wall it will not let you, but as soon as you go to the side of the wall it will let you pass, try it yourself, hope you like it.

I am planning to also implement methods where you cannot go backwards through the wall, or through the sides of the wall, but I have no time right now. Tell me what you think please.

ALICE VERSION 2.2 NEEDED TO VIEW THIS PROGRAM --- USING ALICE 2.0 WILL PRODUCE AN ERROR
If this program produces an error for you, please use x2495iiii's version below, although you will only be able to move forward
Attached Files
File Type: a2w CollisionDetectionTest 2.0.a2w (342.9 KB, 148 views)

Last edited by Dameria; 12-04-2009 at 07:38 PM.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 12-01-2009, 04:19 PM

Not a bad example. There was an error which generated after I let go of the up key, so I fixed that. Here you go.
Attached Files
File Type: a2w CollisionDetectionTest.a2w (271.0 KB, 86 views)


(')>
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 12-01-2009, 04:23 PM

Quote:
Originally Posted by x2495iiii View Post
Not a bad example. There was an error which generated after I let go of the up key, so I fixed that. Here you go.
I'm sorry, but when I tried your program it would not even let me go backwards or to the right, and mine works fine on my computer. Also on yours it goes significantly slower, I don't know what you did. If more people get errors when they let go of the up arrow key, then I will see whats wrong and try to fix it, but yours is not working for me.

Try downloading mine again and try it again. Maybe it downloaded wrong or something, and if it keeps happening then I don't know what would be wrong.

Last edited by Dameria; 12-01-2009 at 04:30 PM.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 12-01-2009, 04:33 PM

Oh yeah. I was hoping you'd see what I did the the forward method and reproduce it when you made the other three directions' collision detection checkers.

You see, the error (which will probably happen to everyone) comes from ending an animation from inside an event by letting go of a key. For some reason, though, it works fine if you use booleans, like upHeld, to trigger and end the animation. For your forward moving method, there was a command for the cube to move for 100000 seconds (or something similar). This is the animation that was ended from inside the event, generating the error. I replaced the method calls in the events with boolean variable changes, which allows you to make the other three directions error-free as well, once they are made. Until then, all it will do is change the respective variables to true while held, and false when released.

Take a look at the moveForward method to see what I mean.

(EDIT: I re-dowloaded your to be sure, but yes, the error is still there. It happens to all "While a key is pressed" events which cut long animations short.)

(EDIT again: You can speed up the motion by changing the meters value in the moveForward method from .05 to something larger, like .1)


(')>

Last edited by x2495iiii; 12-01-2009 at 04:40 PM.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 12-01-2009, 05:09 PM

ok, I never knew that. They seem to work on my computer for some reason.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 12-01-2009, 05:36 PM

Hey, I think I found out your problem. Are you using Alice 2.0? I tried my program on 2.0 and the same error occurred when I tried it there.

I think they fixed that error for Alice 2.2. When using 2.2 I do not get those errors like in 2.0. Also, in 2.2 I cannot do While(true) and put a variable in the true part, and you can in 2.0, that is another reason why I think you might be using 2.0 instead of 2.2

Which version are you using?
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 12-04-2009, 07:43 PM

I have created my final version of the Collision Detection Test (2.0). I have replaced the 2d box with a 3d Rectangular Prism, so it is more realistic. I have also fixed it so that it detects collision from all sides, and not just when trying to move through the front of it. Check it out!

I have deleted my first version in the first post and replaced it with 2.0. I will also have it available in this post, so you can download it from here. I created this to help give people a different perspective in collision detection, although this is mainly only good for when you need collision detection on only 1 building (unless you want to do a lot of work).

I hope you like it, please tell me what you think:

ALICE VERSION 2.2 NEEDED TO VIEW THIS PROGRAM --- USING ALICE 2.0 WILL PRODUCE AN ERROR
If this program produces an error for you, please use x2495iiii's version, but it is not as up-to-date as Collision Detection 2.0
Attached Files
File Type: a2w CollisionDetectionTest 2.0.a2w (342.9 KB, 47 views)

Last edited by Dameria; 12-04-2009 at 10:43 PM.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 12-04-2009, 10:12 PM

Looks great and seems to work great, though the error persists for me.


(')>
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 978
Join Date: Sep 2009
Location: United States
Default 12-13-2009, 06:59 PM

Does this help anybody else understand how to put in collision detection? I think I might even make another world where there are multiple objects, but still only 4 collision detection methods (one for each arrow key movement) in which there is an object parameter in the methods, so you have just have those methods for every object in your game that you want to have collision detection with.

Do you think I should work on that?


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
Zippy133
Guest
 
Status:
Posts: n/a
Default 10-07-2010, 07:10 PM

Hey guys i tried ur program and i tried to copy the boxes and it didnt work. Only the box that was already in the program worked. im doin a school project and trying to make a maze where u cant go throught the walls!!!!
but thats kinda hard so i tried urs and it works fine but i cant duplicate the boxes. how did u get the box to work as a solid

Thanks Guys!!
   
Reply With Quote
Reply

Tags
collision detection

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