I have posted the wrong code. so plz ignore it. below is the right code.
I managed to simulate an avatar walking randomly. however, I wanted the avatar to pick up the cellphone when he reaches the red sphere. I have the code for that but I did not know how to do it in a simulated way (without pressing any key)
this is the code that I am working on:
Code:
import viz
import viznet
import vizinfo
import vizinput
import viztask
import vizact
import vizshape
import vizproximity
import vizmat
viz.go()
viz.go()
viz.MainView.setPosition([0,0.1,0])
viz.setMultiSample(4)
#Increase the Field of View
viz.MainWindow.fov(60)
#avatarRoot = viz.addGroup()
avatarRoot = viz.add('marker.wrl')
cameraLookAtNode = viz.addGroup(parent=avatarRoot, pos=[0, 1.5, 0])
avatar = viz.add('vcc_male.cfg', parent=avatarRoot)
#avatar.state(1)
#viz.collision(viz.ON)
piazza = viz.add('piazza.osgb')
sphere = vizshape.addSphere(radius=0.2)
sphere.setPosition(0,0,20)
sphere.color(viz.RED)
text = viz.addText('radiation source',parent=sphere)
text.setPosition([-0.3,0.3,0])
text.setScale([0.2]*3)
text.color(viz.RED)
text.visible(viz.ON)
text_2D = viz.addText('radiation source area', viz.SCREEN )
text_2D.setPosition(0,0,20)
text_2D.color(viz.RED)
t=text_2D.visible(viz.OFF)
tex = viz.addTexture('logo.jpg')
#maze = viz.add('tankmaze.wrl')
#def onKeyDown(key):
#if key == viz.iskeydown ('t' ):
walk1=vizact.walkTo([4,0,0])
walk2=vizact.walkTo([4,0,3])
walk3=vizact.walkTo([7,0,4])
walk4=vizact.walkTo([8.5,0,17])
walk5=vizact.walkTo([10,0,22])
walk6=vizact.walkTo([3,0,23])
#walk=vizact.walkTo([0,0,15])
def changeState() :
#Add the cellphone model
cell = viz.addChild('phone.3ds')
#Get the right hand bone of the avatar
hand = avatar.getBone('Bip01 R Hand')
#Link the cellphone to the hand
CellLink = viz.link(hand,cell)
#Tweek the cellphone link so it fits snuggly in the hand
CellLink.preTrans( [0.06,-0.08,0.08] )
CellLink.preEuler( [0,0,180] )
#thick = vizact.method()
walks=vizact.sequence(walk1,walk2, vizact.waittime(1),walk3, vizact.waittime(1),walk4, vizact.waittime(1),walk5,vizact.waittime(1),walk6)
viz.collision(viz.ON)
avatar.addAction(walks)
#Make the avatar use the cellphone when the 'w' key is pressed
#vizact.onkeydown('w',avatar.execute,15)
#vizact.onkeydown('t',walk)
#Register the callback which to call the 'onKeyDown' function.
#viz.callback(viz.KEYDOWN_EVENT,onKeyDown)
#Create proximity manager
manager = vizproximity.Manager()
#Add main viewpoint as proximity target
target = vizproximity.Target(avatar)
manager.addTarget(target)
sensor = vizproximity.Sensor( vizproximity.CircleArea(5),source=sphere)
manager.addSensor(sensor)
def EnterProximity(e):
text_2D.visible(viz.ON)
quad = viz.addTexQuad()
quad.setPosition([0,1,20])
quad.texture(tex) # The quad will now display the tree picture
spin=vizact.sequence(vizact.waittime(1), vizact.spin(0,1,0,20))
vizact.addCallback
quad.addAction(spin)
def ExitProximity(e):
text_2D.visible(viz.OFF)
manager.onEnter(sensor,EnterProximity)
manager.onExit(sensor,ExitProximity)