PDA

View Full Version : Stop avatar from walking to its destination


hannahapz
06-15-2018, 11:01 AM
I'm fairly new to Python and Vizard, so the answer to this may be strikingly obvious to some.

I'm trying to stop my pedestrian avatar from walking to a final location as soon as I enter within the bounds of its proximity sensor.

My current code is as follows You can assume I've done all necessary module imports:

def set_avatar_proximity_sensor():
global manager, sensor
manager = vizproximity.Manager()
manager.setDebug(viz.ON)

target = vizproximity.Target(Me)
manager.addTarget(target)

sensor = vizproximity.addBoundingSphereSensor(pedestrian,sc ale=2)
manager.addSensor(sensor)

vizact.onkeydown('d',manager.setDebug,viz.TOGGLE)

def pedestrian_actions():
runAction = vizact.walkTo( [-12, 0, 3] )
pedestrian.addAction (runAction)

def enter_proximity(e):
runAction = vizact.walkTo( [-12, 0, 3] )
pedestrian.addAction (runAction)

set_avatar_proximity_sensor()
vizact.ontimer(0, pedestrian_actions)
manager.onEnter(sensor, enter_proximity)

So, right now, the enter_proximity function is obeyed only after the pedestrian_action function has ended. How do I interrupt the pedestrian_action function however?

hannahapz
06-15-2018, 05:27 PM
I've been able to stop the animation of the avatar's body using an if statement, but otherwise have not been able to stop the avatar's trajectory to a destination.

hannahapz
06-15-2018, 08:38 PM
I solved the issue with a simple if-elif statement

def pedestrian_actions():
ped_position = pedestrian.getPosition()
car_position = car.getPosition()
distance = vizmat.Distance(ped_position, car_position)
runAction = vizact.walkTo( [-12, 0, 3] )
print(distance)

if distance > 4:
pedestrian.addAction (runAction)
elif distance < 2:
pedestrian.clearActions()