View Single Post
  #5  
Old 12-19-2014, 01:14 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You can do an intersection test to find out the height of the ground below the avatar and then adjust the avatar's height:

Code:
'''
Use up/down arrows to move avatar
'''

import viz
import vizact
import vizmat
import vizinfo

viz.setMultiSample(4)
viz.fov(60)
viz.go()

vizinfo.InfoPanel(align=viz.ALIGN_RIGHT_TOP)

viz.clearcolor(viz.SLATE)
viz.addChild('ground.osgb')
viz.move([0,0,-2])

quad = viz.addTexQuad(pos=[0,0,4.5],euler=[0,65,0],scale=[2,10,1],color=viz.RED)
quad2 = viz.addTexQuad(pos=[0,0,13.55],euler=[180,65,0],scale=[2,10,1],color=viz.RED)

avatar = viz.addAvatar('vcc_male2.cfg')
avatar.disable(viz.INTERSECTION)
avatar.state(2)

vizact.whilekeydown(viz.KEY_UP,avatar.setPosition,[0,0,0.03],viz.REL_LOCAL)
vizact.whilekeydown(viz.KEY_DOWN,avatar.setPosition,[0,0,-0.03],viz.REL_LOCAL)

def adjustHeight():
	x,y,z = avatar.getPosition()
	info = viz.intersect([x,y+0.5,z],[x,y-0.5,z])
	groundHeight = info.point[1]
	avatar.setPosition([x,groundHeight,z])
	
vizact.onupdate(0,adjustHeight)
	
view = viz.addView()
view.setPosition([-20,5,9])
view.setEuler([90,15,0])
window = viz.addWindow(view=view)
window.setSize([.4,.4])
window.setPosition([0,1])
Reply With Quote