Alice Community  

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

Reply
 
Thread Tools Display Modes
How do I move a hole randomly within a boundry
Old
brunkdaddy
Guest
 
Status:
Posts: n/a
Default How do I move a hole randomly within a boundry - 05-06-2010, 02:25 AM

Hi Guys,

I have forum surfed this issue for hours now and I can't figure it out.
The issue is I have a box that a contains a hole, this hole must move randomly around inside the box (with duration 0) but can never return to the centre of the box (where it started). My Alice code looks like this atm (note: the distance from the centre of the box to each side of the box is 10m):

If hole distance to centre > 10
(stuck here, but I want it to move to a random spot in the box)

Else
hole move left random number minimum = -10 maximum = 10
hole move forward random number minimum = -10 maximum = 10

Any help would be greatly apperciated!
   
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 05-06-2010, 03:38 PM

Make four number variables, leftVar, rightVar, upVar, and downVar

Place four squares with their against each edge of the box, making sure to keep the square's centers touching the bottom of the box.

Then you'd need a complex method that might looks something like this:

rightVar set value to circle dist from right square - circle's width

leftVar set value to circle dist from left square - circle's width

(etc. for the other two variables)

Loop infinity times:
circle move right [random number [min = -leftVar] [max = rightVar] [integerOnly = false]] meters
circle move up [random number [min = -downVar] [max = upVar] [integerOnly = false]] meters


That should do it.


(')>
   
Reply With Quote
screenshot
Old
brunkdaddy
Guest
 
Status:
Posts: n/a
Default screenshot - 05-07-2010, 08:39 PM

Thanks for the reply,

I tried to do what you said as best I could but it didn't seem to work - I have posted a link to a screenshot of the code but to help ill do a diagram too:

nwPost.........................................neP ost



.......................centre..................... .....



swPost.........................................seP ost

the hole has to move around but not go outside the box outlined by the posts.

here is the link: http://yfrog.com/20screenshot20100508at103p

Cheers.
   
Reply With Quote
Reply

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.