Finding/shifting forwardVector into another vector.

Come on, this is Panda. Why would you ever need to go to matrices? :slight_smile:

You can do with with HPR’s, like this:

# Get the current orientation, as a hpr
currentHpr = self.shipNodePath.getHpr()

# Get the orientation needed to face the target
self.shipNodePath.lookAt(self.target)
targetHpr = self.shipNodePath.getHpr()
self.shipNodePath.setHpr(currentHpr)

# Make sure the hpr's are both on the same side of the circle.
targetHpr = VBase3(fitDestAngle2Src(currentHpr[0], targetHpr[0]),
                   fitDestAngle2Src(currentHpr[1], targetHpr[1]),
                   fitDestAngle2Src(currentHpr[2], targetHpr[2]))

# Now rotate a bit torwards the target.
self.shipNodePath.setHpr(currentHpr + turn_ratio * (targetHpr - currentHpr))

That will linearly interpolate HPR angles componentwise, which works OK but it does require that weird call to fitDestAngle2Src (to prevent the rotation from going the wrong way around the circle). (fitDestAngle2Src is in direct.showbase.PythonUtil.) You can do exactly the same thing with quaternions instead, which tends to give a better result and doesn’t require that strange call:

# Get the current orientation, as a quaternion
currentQuat = self.shipNodePath.getQuat()

# Get the orientation needed to face the target
self.shipNodePath.lookAt(self.target)
targetQuat = self.shipNodePath.getQuat()
self.shipNodePath.setQuat(currentQuat)

# Now rotate a bit torwards the target.
self.shipNodePath.setQuat(currentQuat + turn_ratio * (targetQuat - currentQuat))

Of course, this assumes that you have a task-based system that will be making this call every frame with a small value of turn_ratio. If you can use an interval-based system instead, it’s even easier; just create a LerpQuatInterval and let it do all the work for you. :slight_smile:

David