WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-13-2013, 12:15 PM
Ducky Ducky is offline
Member
 
Join Date: Jul 2012
Location: Birmingham, AL
Posts: 7
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)
Reply With Quote
  #2  
Old 03-01-2013, 01:23 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Your code is not applying a walkto action to the avatar. Where/when do you want the avatar to walk?
Reply With Quote
Reply


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
Has user perception of avatar expressions been tested? Karla Vizard 3 10-28-2008 11:32 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
Avatars in an array and link/unlink betancourtb82 Vizard 7 09-05-2006 05:06 PM


All times are GMT -7. The time now is 02:23 AM.


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