![]() |
|
#1
|
|||
|
|||
|
Hi I need help trying to figure out how can you tell when an avatar enters a proximity sensor. Once the avatar enters the proximity its health is supposed to deplete. I'm not really sure where to start. Is there a way to tell when a sensor enters another sensor?
|
|
#2
|
|||
|
|||
|
Just make your avatar a vizproximity Target
![]() Code:
target = vizproximity.Target(avatar)
manager.addTarget(target)
def EnterProximity(e):
if e.target == target:
print "Avatar is losing health"
manager.onEnter(None, EnterProximity)
|
|
#3
|
|||
|
|||
|
Oh! Wow thanks! I had no idea we could do that!
|
|
#4
|
|||
|
|||
|
Proximity Sensor Event
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.
![]() Code:
sensor = vizproximity.Sensor(vizproximity.Sphere(15,center = [72,-.57,2]), source = avatar1) manager.addSensor(sensor) Avatar2Target = vizproximity.Target(avatar2) Avatar2Manager.addTarget(Avatar2Target) def HealthLoss(e): if e.target == Avatar2Target: print "Sensor Entered" Avatar2Manager.onEnter(sensor1, HealthLoss) |
|
#5
|
|||
|
|||
|
Quote:
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()
Created in Vizard 4. |
|
#6
|
|||
|
|||
|
Wow thanks! that's really helpful. So if I want the health to continue to drop until I exit the proximity would i just do a While(true) loop?
|
|
#7
|
|||
|
|||
|
Quote:
Code:
health = 100 healthloss = False def onEnter(e): if e.target == target: healthloss = True def onExit(e): if e.target == target: healthloss = False manager.onEnter(sensor, onEnter) manager.onExit(sensor, onExit) # Demo def update(): if healthloss: health -= 2 * viz.elapsed() |
![]() |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unexpected Avatar lookAt() behavior when using yield statements | chris2307 | Vizard | 2 | 12-17-2013 03:58 AM |
| Avatar & Motion Capture Interface | Angie | Vizard | 1 | 08-05-2010 07:17 PM |
| Collision of an avatar with a quad | Frank Verberne | Vizard | 8 | 06-04-2008 10:44 AM |
| Looking through the eyes of an avatar | Frank Verberne | Vizard | 2 | 04-01-2008 06:52 AM |
| How to make avatar's eyes to blink when speaking | michelcm3 | Vizard | 12 | 01-15-2008 09:48 AM |