#1
|
|||
|
|||
Avatar w/ hat cannot look at viewpoint
Hello, I was trying a combination of scripts from tutorials... the first one was the one to bind the hat to an avatar, and the second was to make the avatar look at the viewpoint. My problem is, I can't get them to work at the same time for some reason. :/
Here is the hat code I am using: Code:
patient=viz.add('vcc_male.cfg') patient.translate(-5.1,0,8.9) patient.rotate(0,1,0,180) patient.state(1) hat = viz.add('tophat.3ds') head2 = patient.getBone('Bip01 Head') HatLink = viz.link(head2,hat) HatLink.preTrans( [0,0.150,0.01] ) HatLink.preEuler( [0,-10,0] ) toon = viz.add('toon.dlm') patient.modify(toon) Code:
#Get a handle to the Neck bone head = patient.getBone('Bip01 Neck') head.lock() #Disable automatic bone animation so that we can manually animate it #Lock the head bone so that manual movement of the neck bone also moves the child head bone patient.getBone('Bip01 Head').lock() #Used to rotate the torso when the viewpoint moves to the side of the avatar torso = patient.getBone('Bip01 Spine1') torso.lock() def ontimer(num): #Make head look at viewpoint viewPOS = viz.MainView.getPosition() head.lookat( viewPOS, 0, viz.AVATAR_WORLD ) #points the head and neck at the viewpoint #Get neck orientation to see if we need to translate torso headOrientation = head.getEuler( viz.AVATAR_LOCAL ) #Move torso so that the neck does not twist too much if headOrientation[0] < -90 and headOrientation[0] > -180: # -90 to -180 #Viewpoint in avatar's left-back yaw quadrant torso.setEuler( headOrientation[0] + 90, 0, 0, viz.AVATAR_LOCAL ) #Point head back at view because it is child object and was moved by torso rotation head.lookat( viewPOS, 0, viz.AVATAR_WORLD ) elif headOrientation[0] > 90 and headOrientation[0] < 180: #90 to 180 #Viewpoint in avatar's right-back yaw quadrant torso.setEuler( headOrientation[0] - 90, 0, 0, viz.AVATAR_LOCAL ) #Point head back at view because it is child object and was moved by torso rotation head.lookat( viewPOS, 0, viz.AVATAR_WORLD ) viz.callback( viz.TIMER_EVENT, ontimer ) viz.starttimer( 1, 0, viz.PERPETUAL ) |
#2
|
|||
|
|||
It works for me. What exactly is the problem you are experiencing?
|
#3
|
|||
|
|||
Hmm, that's funny... On my level I have made, the patient does not do that. I thought for sure it was the hat that screwed up. Sorry, I'll keep looking into it and come here if I figure out what the problem really is
|
#4
|
|||
|
|||
I've found out that there's another code conflicting with the avatar's looking patterns for some reason... It's the callback for when I put the arrow following the player's movement in the Bird's Eye view.
Note: The map I'm using for this thing is room.wrl, so the Bird's Eye is tweaked so that it is specifically for that level. Code:
# Create a new window in the upper right corner UpperRightWindow = viz.add(viz.WINDOW) UpperRightWindow.position(0.75, 1.0) UpperRightWindow.size(0.3, 0.3) UpperRightWindow.visible(0,viz.SCREEN) # Create a new viewpoint BirdView = viz.add(viz.VIEWPOINT) #Attach the bird's eye view to the upper right window UpperRightWindow.viewpoint(BirdView) #Move the view above the center of the room BirdView.translate(-1,20,2) #Rotate the view so that it looks down BirdView.rotate(1,0,0,90) arrow = viz.add('arrow.wrl') arrow.scale(0.5,0.5,0.5) def mytimer(num): #Get the current head orientation and position ori = viz.get(viz.VIEW_YAW) pos = viz.get(viz.HEAD_POS) # #Move the rear view to the current position # RearView.translate(pos) # # #Rotate the rear view so that it faces behind us # RearView.rotate(0,1,0,ori+180) # #Move the arrow to our current location arrow.translate(pos[0],3.3,pos[2]) arrow.rotate(ori,-90,0) # Disable collisions with the arrow arrow.disable(viz.COLLISION) # Create callback to a timer and start it viz.callback(viz.TIMER_EVENT,mytimer) viz.starttimer(0,0.001,-1) |
#5
|
|||
|
|||
You are using two different timer callbacks. So the last one that is being registered is overwriting the first one. You are better off using the vizact.ontimer function to register multiple timer events that do not conflict with each other. Your code would look something like this:
Code:
def ArrowTimer(): #Place code that updates arrow here pass vizact.ontimer(0,ArrowTimer) def AvatarLookTimer(): #Place code that update avatar head here pass vizact.ontimer(0,AvatarLookTimer) |
#6
|
|||
|
|||
Thanks farshizzo, it works like a charm now!
|
Thread Tools | |
Display Modes | Rate This Thread |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Avatars in an array and link/unlink | betancourtb82 | Vizard | 7 | 09-05-2006 05:06 PM |
VRML Viewpoint error | bstankie | Vizard | 1 | 03-11-2003 03:10 PM |