View Single Post
  #7  
Old 05-30-2008, 10:45 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Here is a sample script that shows how to setup collisions with the right hand of the avatar. Adding support for other body parts should not be too difficult.
Code:
import viz
viz.go()

#Enable physics
viz.phys.enable()

#Create ground plane
ground = viz.add('tut_ground.wrl')
ground.collidePlane()

#Create static box in front of avatar
box = viz.add('box.wrl',scale=[2,2,2],pos=(0,1,1.7))
box.collideBox()
box.disable(viz.DYNAMICS)

#Create avatar that doesn't like big boxes
avatar = viz.add('vcc_female.cfg')
avatar.state(6)

#Create a collision box and link it to right hand of avatar
rHandBox = viz.add('box.wrl',scale=[0.1,0.1,0.1])
rHandBox.collideBox()
rHandBox.disable(viz.DYNAMICS)
rHandBox.enable(viz.COLLIDE_NOTIFY)
rHandLink = viz.link( avatar.getBone('Bip01 R Hand') , rHandBox )
rHandLink.preTrans([0.05,-0.05,0])

#Comment this line out if you want to see the collision box around the hand
rHandBox.disable(viz.RENDERING)

#List of colors to cycle through
colors = viz.cycle([viz.WHITE,viz.BLUE,viz.RED])

#Change color of box when avatar hits it
def onCollideBegin(e):
	if e.obj1 == rHandBox:
		if e.obj2 == box:
			box.color(colors.next())
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin)

#Setup camera navigation
import vizcam
vizcam.PivotNavigate(center=[0,1,0],distance=5)
Reply With Quote