charater lookAt problem

Hello, I got control of my game NPC head bone, and used lookAt so he could look at the player charater node while the player walks. But what I got was a very weird bone behavior, which wasn´t what I wanted, some of the code I think its important is below with images:

self.npc1_head = self.npc1Actor.controlJoint( None, 'modelRoot', 'head' )

self.playerhead = render.attachNewNode( 'playerhead' )

self.playerhead.setPos( self.player.getX(), self.player.getY(), self.player.getZ()+1 )
			
self.npc1_head.lookAt( self.playerhead  )

Any help on getting the NPC really look to the player charater properly is welcome.

The problem is that the controlJoint node transform should be specified in the node’s local transform space, but it is by default parented directly to the character’s root. This means if the node you are controlling is not at the root of the skeleton, the net transform is incorrect.

The easiest workaround is to also call exposeJoint() on the parent joint for ‘head’, and then parent the controlJoint node to that. Something like this:

self.npc1_head = self.npc1Actor.controlJoint( None, 'modelRoot', 'head' ) 
headParent = self.npc1Actor.exposeJoint(None, 'modelRoot', 'headParent')
self.npc1_head.reparentTo(headParent)

David

Well, the behavior of the head got a little better, but it is still weird. By the way, thanks for the help drwr

#inside a def
self.npc1_head = self.npc1Actor.controlJoint( None, 'modelRoot', 'head' )

self.headParent = self.npc1Actor.exposeJoint(None, 'modelRoot', 'torax') 

self.npc1_head.reparentTo( self.headParent ) 

self.playerhead = render.attachNewNode( 'playerhead' )

#inside task
self.playerhead.setPos( self.player.getPos() )
			
self.npc1_head.lookAt( self.playerhead ) 

What could be this time?

The lookAt() function call moves the y-axis to point in the indicated direction. Since your model was created presumably with a y-up orientation, that means the y-axis is pointing out of the top of your character’s head, so lookAt() rotates the top of her head to look at the other character.

You’ll need to model your head so that the y-axis is pointing down her nose. That means you’ll need to add a new transform to the skeleton to counter-rotate the head back down.

David

My model was created in blender and exported with chicken, with a Z up, X side and Y for depth. Below is a screenshot of the set up.


But as you said the head acts like y axis was up, I tried just to test rotating model and esqueleton in various orientations and the behavior is the same

add a new transform to counter-rotate the head back down? I´m sorry, but could you explain better?

Again, thanks for the help

Without remodeling, you can insert two new joints: one above the head joint, and one below it. These joints can both have a static transform: the one above rotates 90 degrees one way, and the one below rotates 90 degrees the other, to convert Y-up to Y-forward and vice-versa.

Or, you can freeze the 90-degree transform onto the head’s vertices, and then reanimate the head to compensate for the new transform.

David