#1
|
|||
|
|||
executing a turn in the middle of a walkto action
The goal of the program is to simulate repulsion by making an avatar walk around the world randomly unless it comes near another object (in this case, a lamp), at which point it turns around to reverse its path and walk away from the object. I am having trouble coding the turn and am not sure if there are better commands to use in the Viz library or if the entire way I'm setting up my timers to detect a repulsive object is wrong.
Here is the relevant code. ___________________________________________ # Starts the timers when the user presses '1' def onkeydown(key): if key == '1': viz.starttimer(START_WALK, 6, viz.FOREVER) #Starts avatars walking to a random point, updates that random point every six seconds # Timer functionviz.starttimer(START_REPULSION, 0.1, viz.FOREVER) #Checks for and enacts any repulsions every 0.1 seconds def ontimer(num): if num == START_WALK: randWalk() if num == START_REPULSION: viz.callback(viz.KEYDOWN_EVENT, onkeydown)repulseObjects() viz.callback(viz.TIMER_EVENT, ontimer) # Function: Makes each avatar in the environment walk to a random point def randWalk(): for item in avatarList: walk = vizact.walkto(getRandom(), 0, getRandom()) # Function: Causes the avatars to turn around if they get too close to the lampsitem.runAction(walk) def repulseObjects(): for i in lampList: # Lamps are the 'repulsive objects' -- there are several in the world for j in avatarList: # This is a list of all the avatar objects. if distance(i.getPosition(), j.getPosition()) < 4: # Notes on other functions:# HERE IS WHERE A TURN WOULD BE EXECTED, BUT I DON'T KNOW WHAT CODE TO USE. # - getRandom() returns a float within a range of points # - distance(list1, list2) returns the distance between two points; the lists are sets of coordinates ______________________________________ Any help on what commands are available to execute a turn-around and reverse path would be much appreciated. If there's a better way to set up the entire randomwalk/repulsionturnaround scheme, that would be great to hear about as well. Thanks a lot! christopher lin Last edited by v-clizzin; 09-18-2006 at 12:10 PM. |
#2
|
|||
|
|||
What is the behevior of the Avatar when it should turn around?
Try stoping the currenly running actions with myAvatar.clearActions() then applying the new walkto action.
__________________
Paul Elliott WorldViz LLC |
Thread Tools | |
Display Modes | Rate This Thread |
|
|