alice-teacher Collision and walking speed questions

Edward Bujak edward_bujak at hotmail.com
Fri Sep 6 10:07:41 EDT 2013


1.No native support in Alice 2.x to support true object collision.BTW, great link about similar sized spherical collisions via Dr. James Vanderhyde (below).With most objects there is a height, width, depth.With sphere's the height,width,depth are the same and typically referred to as the radius.Also with sphere's the object's origin is at the center making it easier to determine true collision.Call the spherical objects ball1 and ball2.Note: you cannot simply say when the distance between the balls is 0 then there is a collision when in fact they are exactly in the same 3-Dimensional position within each other ... so you need to add the lengths of the 2 (possibly different) radii to be the distance when a collision has occurred:Create an event:if (ball1.distance to (ball2)  == (ball1.width + ball2.width))     collision = trueelse     collision = false
Note: This should be improved to not compare floating point numbers with an inequality.if (ball1.distance to (ball2)  <=  (ball1.width + ball2.width))     collision = trueelse     collision = false Note:  The above is for 2 spheres of any size.  If you are detecting collision amongst various spheres you will have to have a more involved collection of spheres and iterate all collisions. With 2 spheres there is 1 conditional.With 3 spheres there are 3 conditionals (1+2).  With 4 spheres there are 6 conditionals (1+2+3).  With 5 spheres there are 10 conditionals (1+2+3+4).  With N spheres there are (1+2+3+ ... + N-1) conditionals.
Note: This becomes more involved with non-spherical objects where the orientation of the two objects along with their components of height, width, and depth between the two objects becomes important.
2.Assuming you still want the cursor keys to control the movement of an object (call it personJoe) forward-back-left-right and other keys for up-down:[a] Create a variable to control personJoe's speed (assume uniform speed in all six directions), call it distancePerCursorClick, initialize it to 0[b] Create an event bound to the 'S' key to decrease personJoe's speed:distancePerCursorClick = distancePerCursorClick - 1[c] Create an event bound to the 'F' key to increase personJoe's speed:distancePerCursorClick = distancePerCursorClick + 1[d] Create an event for each of the six cursor keys similar to this:When the up cursor is clicked     move personJoe up by the distance distancePerCursorClickNote: you can package this idea anyway you want, but this is the basic idea.Note: be careful that repeated clicking of the 'S' key can make the distancePerCursorClick become negative and hence your movement keys will make personJoe act backwards from the clicked cursor key 
Not: you do not have to have uniform speed in all directions.  In this case, create three variables:distancePerUpDownCursorClickdistancePerLeftRightCursorClickdistancePerForwardBackCursorClick
--Ed Bujak
From: jvanderhyde at benedictine.edu
To: alice-teachers at lists.andrew.cmu.edu
Date: Thu, 5 Sep 2013 13:28:28 +0000
Subject: Re: alice-teacher Collision and walking speed questions






1. Collision detection in Alice is tricky. I have had students try several different approaches, but nothing has really worked as well as I would like. There are some tutorials you can read (I found it with a Google search):
http://programminginalice.wordpress.com/tag/collision-detection/



2. I don't think there's any way to modify those existing controls, so you have to write your own controls for the player object. One non-obvious feature that will be useful is that you can right-click on events (such as "when a key is typed") and change
 it to something else ("while a key is pressed").



James





--
Dr. James Vanderhyde
Math and Computer Science
Benedictine College
jvanderhyde at benedictine.edu
http://vanderhyde.us/~james/pro/








On Sep 4, 2013, at 12:46 PM, Lori Fuller <lori.fuller at browardschools.com> wrote:



I have an advanced student among all of my beginners... and he is working on a maze game.
2 questions:
1.   In Alice 2.3, is it possible to set up a collision indication method? If so, where do I find information on this?
2.  Is there a way to slow down the person object walking while using the arrow keys as controllers?






thanks,


Lori Fuller, M.Ed.
Monarch High School
Career Technology Department Head
Technology Coordinator
Asst. Athletic Director


"A posse ad esse", from possibility to actuality...


Big brother is watching so watch what you put in the email!


Under Florida law, e-mail addresses, and all communications, including e-mail communications, made or received in connection
 with the transaction of School Board business are public records, which must be retained as required by law and must be disclosed upon receipt of a public records request, except as may be excluded by federal or state laws.  If you do not want your e-mail
 address released in response to a public records request, do not send electronic mail to this entity. Instead, contact this office by phone or in writing.




_______________________________________________

alice-teachers mailing list

alice-teachers at lists.andrew.cmu.edu

https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers










_______________________________________________ alice-teachers mailing list alice-teachers at lists.andrew.cmu.edu https://lists.andrew.cmu.edu/mailman/listinfo/alice-teachers 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20130906/c322b433/attachment.html 


More information about the alice-teachers mailing list