View Full Version : Distance or position based event?
vissimutah
08-25-2009, 11:38 AM
We're trying to play a sound when the viewpoint reaches a certain point in the virtual environment. Do we have to register a custom event to do this? Is there a way to use a loop without freezing the program?
farshizzo
08-25-2009, 12:26 PM
It seems like you simply want to run some code every frame. In that case you can register a timer function, which will be called every frame. Here is an example that plays a sound when the Z position of the view passes 3 meters:import viz
viz.go()
viz.add('tut_ground.wrl')
def CheckView():
"""Plays a sound when Z position of view is greater than 3"""
x,y,z = viz.MainView.getPosition()
if z > 3:
# Play sound and unregister timer function
viz.playsound('elaugh1.wav')
return vizact.EventRemove
vizact.ontimer(0,CheckView)
vBulletin® v3.8.7, Copyright ©2000-2025, vBulletin Solutions, Inc.