Alice Community IF/Else and Collision

 IF/Else and Collision
 Sharpie Junior Member   Status: Offline Posts: 12 Join Date: Mar 2014 IF/Else and Collision - 04-10-2014, 09:24 PM Greetings Alice Community, have a couple of questions if anyone is willing to help! 1 How do I get the "distance to" function to work in relevance to another object in Alice? 2 How do I get the "within distance" function to work inside an If/Else statement without canceling or ignoring the IF code? 3 How can I keep multiple random-moving objects from colliding into each other by using "distance to" function? Pretty much puzzled over these IF/Else statements. The coding looks logical but each time I run they end up canceling out. Please help! Last edited by Sharpie; 04-10-2014 at 09:29 PM.
 Hi, here's one way!
 jrrTolkien Senior Member     Status: Offline Posts: 166 Join Date: Feb 2014 Location: Middle-Earth (Merrimack, NH) Hi, here's one way! - 04-11-2014, 12:18 PM One way is if you drag in an if/else, then say if (object) is within .5 meters of (other object), do nothing, else (move forward). If you are still confused, I can make an Alice world as an example and post it up here. -jrr
 Also
 MrMoke Senior Member     Status: Offline Posts: 501 Join Date: Sep 2007 Location: Austin, Texas Also - 04-11-2014, 02:30 PM Also remember that each object has a origin-point, distances are measured between those single points, and that the points aren't always in the middle. For example, drag an Egyptian into a scene, and then a simple sphere. If you then tell the sphere to set it's "point of view" to the Egyptian, it's center will move to the Egyptian's feet. Now shrink the ball to knee height. So, if you are checking for a distance that is less than the height of the Egyptian, the ball could easily pass through the head, but never come close to the feet. The problem isn't as pronounced with some larger objects like buildings, but can be a challenge. Try an experiment: 1) Drag two spheres of "different" sizes into a scene(maybe on left and right sides of view screen). 2) Build a loop of your choice that moves the balls toward each other in small measured increments while the distance between the two is > the sum of the two radii. 3) If they stop when they touch, you win. It might sound like a lot of work, but if you have a large "list" of different objects of differing sizes, it might come in handy.
Sharpie
Junior Member

Status: Offline
Posts: 12
Join Date: Mar 2014
04-12-2014, 02:14 PM

Quote:
 Originally Posted by jrrTolkien One way is if you drag in an if/else, then say if (object) is within .5 meters of (other object), do nothing, else (move forward). If you are still confused, I can make an Alice world as an example and post it up here. -jrr
Would be great if you could provide an example! I have a similar code that i've been working on. The bunny object ignores the spring in the if segment and keeps on hopping in the else instead.

@MrMoke

Thanks Moke! I've tried your suggestion but I got lost in the math function part. When I tried to drag and drop it it from World menu the function wasn't green and it wouldn't let me select it. Is there a part that I am missing like a placeholder?

Last edited by Sharpie; 04-12-2014 at 02:44 PM.

 It's Tricky, but only the first time.
 MrMoke Senior Member     Status: Offline Posts: 501 Join Date: Sep 2007 Location: Austin, Texas It's Tricky, but only the first time. - 04-12-2014, 06:50 PM Ifs and Whiles require a Boolean response (true or false), so dragging in any logical test satisfies the start, even (1>1). Dragging a numeric function like "distanceTo" into either side gives one numeric value, so A.distanceTo(B) > 1. Use the down arrow on the opposite side, select math and change it to 1+1, so A.distanceTo(B) > ( 1 + 1). Lastly, use the same technique to replace the ones with A.getWidth()/2 and B.getWidth()/2, so while(A.distanceTo(B) > ( (A.getWidth()/2)+(B.getWidth()/2) ) Probably seems like a lot of work, but if you have a routine that's constantly checking one object's distance to a list or array of 20 others, it requires negligible additional coding. You just replace say "B" with a reference to a list item.
 Example
jrrTolkien
Senior Member

Status: Offline
Posts: 166
Join Date: Feb 2014
Location: Middle-Earth (Merrimack, NH)
Example - 04-17-2014, 03:50 PM

Here's an example for you. This is a little world I made. Take a look at it, but it's a little sloppy. You should still be able to read it, though.

-jrr
Attached Files
 8bitfun.a2w (246.8 KB, 12 views)

 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