| Ducky | 
			02-13-2013 12:15 PM | 
		 
		 
		 
		
			Avatar eye contact with user as it moves   
		
		
		I am looking at the sample WatchNode code. I removed the ball code and changed the nodeToLookAt in line 74 to viz.MainView. I also changed the avatar's state to (1). This makes the avatar's head follow me as I move around, which is the first thing I want. However, I seem to keep failing when I try to then make the avatar move/walkTo somewhere while still looking at me. I am missing something small here but that's b/c I am a newbie I am sure. Thanks for the help. 
	Code: 
	
 import viz 
import vizact 
 
viz.setMultiSample(8) 
viz.fov(60) 
viz.go(viz.FULLSCREEN) 
 
class WatchNodeAction(viz.ActionClass): 
    """Makes avatar head follow node object around""" 
 
    def begin(self,object): 
        """Called once when action starts""" 
 
        #Get the node the avatar should look at 
        self.nodeToLookAt = self._actiondata_.data[0] 
        #Get time the avatar will look at object 
        self.duration = self._actiondata_.data[1] 
        self.headBone = self._actiondata_.data[2] 
        self.blendIn = self._actiondata_.data[3] 
 
        self.timeElapsed = 0 
 
        #Get the head bone and lock it 
        self.head = object.getbone(self.headBone) 
        self.head.lock() 
 
        self.startQuat = self.head.getQuat() 
 
    def update(self,elapsed,object): 
        """Called every frame to update action""" 
 
        self.timeElapsed += elapsed #time avatar has looked at node 
 
        p = self.timeElapsed / self.blendIn 
 
        #If looking for a finite duration, check if time has passed 
        if self.duration > 0.0 and self.timeElapsed > self.duration: 
            #duration passed, end action 
            self.head.lookAt( self.nodeToLookAt.getPosition(), 0, viz.AVATAR_WORLD ) 
            self.end(object) #End the action and clear it from the action queue 
 
        elif p < 1.0: 
            #blend in head look 
            self.head.lookAt( self.nodeToLookAt.getPosition(), 0, viz.AVATAR_WORLD ) 
            targetQuat = self.head.getQuat() 
 
            nextQuad = vizmat.slerp(self.startQuat,targetQuat,p) 
            self.head.setQuat(nextQuad) 
 
        else: 
            #Done with blend in, just look at node 
            self.head.lookAt(self.nodeToLookAt.getPosition(), 0, viz.AVATAR_WORLD) 
 
    def end(self,object): 
        if self.head: 
            self.head.unlock() 
        viz.ActionClass.end(self,object) 
 
#Function to construct the action instance 
def watchNode( nodeToLookAt, duration = viz.FOREVER, headBone = 'Bip01 Head', blendIn = .2 ): 
    action = viz.ActionData() 
    action.data = [ nodeToLookAt, duration, headBone, blendIn ] 
    action.actionclass = WatchNodeAction 
    return action 
 
viz.MainView.setPosition( 0, 0, 0 ) 
 
male = viz.add( 'vcc_male.cfg' ) 
male.setPosition( 0, -1.5, 2 ) 
male.setEuler( 180, 0, 0 ) 
male.state(1) 
 
#Apply the action to the avatar 
male.addAction( watchNode(viz.MainView, viz.FOREVER) ) 
 
def endHeadWatch(): 
    #blend head to neutral orientation 
    head = male.getBone('Bip01 Head') 
    headQuat = head.getQuat(viz.AVATAR_LOCAL) 
    male.endAction() 
    head.lock() 
    head.setQuat(headQuat, viz.AVATAR_LOCAL) 
    male.addAction( vizact.headto( 0,0,0, 20, bone = 'Bip01 Head'), 1 ) 
 
vizact.onkeydown(' ',endHeadWatch) 
  
	 |