WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   executing a turn in the middle of a walkto action (https://forum.worldviz.com/showthread.php?t=748)

v-clizzin 09-18-2006 01:02 PM

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
viz.starttimer(START_REPULSION, 0.1, viz.FOREVER) #Checks for and enacts any repulsions every 0.1 seconds
# Timer function
def ontimer(num):
if num == START_WALK:
randWalk()
if num == START_REPULSION:
repulseObjects()
viz.callback(viz.KEYDOWN_EVENT, onkeydown)
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())
item.runAction(walk)
# Function: Causes the avatars to turn around if they get too close to the lamps
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:
# HERE IS WHERE A TURN WOULD BE EXECTED, BUT I DON'T KNOW WHAT CODE TO USE.
# I'VE TRIED:
# turnAround = vizact.spin(0,1,0,90,2)
# j.runAction(turnAround)
# I'VE TRIED:
# j.execute(3)
# I'VE TRIED:
# j.rotate(0,1,0,180)
# NONE OF THESE PRODUCE THE DESIRED EFFECT OF GETTING THE AVATAR TO TURN AROUND AND WALK AWAY FROM THE LAMP
# Notes on other functions:
# - 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

Gladsomebeast 09-18-2006 03:31 PM

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.


All times are GMT -7. The time now is 03:59 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC