WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-06-2015, 10:47 AM
BSUGeek BSUGeek is offline
Member
 
Join Date: Oct 2014
Posts: 23
Question Proximity event when avatar enters

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?
Reply With Quote
  #2  
Old 04-07-2015, 08:05 AM
Erikvdb Erikvdb is offline
Member
 
Join Date: May 2013
Posts: 63
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)
*Code assumes you have already set up your proximity manager, avatar and sensor(s).
Reply With Quote
  #3  
Old 04-07-2015, 08:07 AM
BSUGeek BSUGeek is offline
Member
 
Join Date: Oct 2014
Posts: 23
Oh! Wow thanks! I had no idea we could do that!
Reply With Quote
  #4  
Old 04-14-2015, 09:43 AM
sportykourty sportykourty is offline
Member
 
Join Date: Mar 2015
Posts: 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)
Reply With Quote
  #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
  #6  
Old 04-16-2015, 08:32 AM
sportykourty sportykourty is offline
Member
 
Join Date: Mar 2015
Posts: 4
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?
Reply With Quote
  #7  
Old 04-21-2015, 12:53 AM
Erikvdb Erikvdb is offline
Member
 
Join Date: May 2013
Posts: 63
Quote:
Originally Posted by sportykourty View Post
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?
No, entering and exiting a proximity are two separate events. Use them to toggle a state that you can check for in the general update loop.

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()
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unexpected Avatar lookAt() behavior when using yield statements chris2307 Vizard 2 12-17-2013 02:58 AM
Avatar & Motion Capture Interface Angie Vizard 1 08-05-2010 06:17 PM
Collision of an avatar with a quad Frank Verberne Vizard 8 06-04-2008 09:44 AM
Looking through the eyes of an avatar Frank Verberne Vizard 2 04-01-2008 05:52 AM
How to make avatar's eyes to blink when speaking michelcm3 Vizard 12 01-15-2008 08:48 AM


All times are GMT -7. The time now is 12:42 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC