View Single Post
  #5  
Old 04-15-2015, 01:54 AM
Erikvdb Erikvdb is offline
Member
 
Join Date: May 2013
Posts: 63
Quote:
Originally Posted by sportykourty View Post
So I was trying to incorporate the previous code but I'm stuck. does my sensor and target have to be in the same manager? I'm not really sure what I'm doing wrong but the function never executes.
Yes, all targets and sensors that interact with each other have to be assigned to the same manager.

Here's a complete code example:
Code:
import viz
import vizact
import vizproximity

# Physical Objects
ball = viz.addChild('beachball.osgb',pos=[-1,0.2,0])
avatar = viz.addAvatar('vcc_male2.cfg',pos=[1,0,0])
avatar.setEuler([180,0,0])
avatar.state(5)

# Proximity Management
manager = vizproximity.Manager()
manager.setDebug(viz.ON)

sensor = vizproximity.Sensor(vizproximity.Sphere(0.5, center=[0,0,0]), ball)
manager.addSensor(sensor)

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

def healthLoss(e):
	if e.target == target:
		print "Sensor Entered"
		
manager.onEnter(sensor, healthLoss)

# Demo
def update():
	if viz.key.isDown(viz.KEY_LEFT):
		avatar.setPosition([-2*viz.elapsed(),0,0],viz.REL_GLOBAL)
	elif viz.key.isDown(viz.KEY_RIGHT):
		avatar.setPosition([2*viz.elapsed(),0,0],viz.REL_GLOBAL)
		
vizact.ontimer(0,update)

viz.MainView.setPosition([0,1,-4])
viz.go()
Use arrow keys to move the avatar to the ball.
Created in Vizard 4.
Reply With Quote