Ah, so you're talking about the NPC looking at the Player? In that case, you need to run the code from the perspective of the NPC. I've turned the code into a function that should be able to be used on any character.
+ Code Snippetfunction CharLookAt(charObj, charHeadBone, targetVector ref as tVector3)
// get character and target on XZ plane
charPos as tVector3
targetPos as tVector3
charPos = ObjectPositionToVector3(charObj)
targetPos = targetVector
charPos.y = 0
targetPos.y = 0
// get vector pointing from character to target on XZ plane
dVec as tVector3
dVec = Vector3Subtract(targetPos, charPos)
// normalize it
dVec = Vector3Normalized(dVec)
// get character direction on XZ plane (heading vector)
hVec as tVector3
hVec = YAngleToHeadingVector3(GetObjectAngleY(charObj))
// get dot product of character heading and heading toward target
hvDot# = Vector3DotProduct(dVec, hVec)
// if dot product < 0, then angle from character to target > 90 degrees
if hvDot# >= 0.0
setObjectBoneLookAt( charObj, charHeadBone, targetVector.x, targetVector.y, targetVector.z, 0 )
else
// I'm not sure about this code here, but the idea is to just set the head back to normal if it's out of range
setObjectBoneRotation( charObj, charHeadBone, 0, 0, 0)
endif
endfunction
you can call it like this:
+ Code SnippetlookTarget as tVector3
lookTarget.x = bonex#
lookTarget.y = boney#
lookTarget.z = bonez#
CharLookAt(Taurus, headBone, lookTarget)
Let me know if it works. I haven't tested it myself because I'd need to setup a character for it to do so.
[edit] updated some of the variable names to make more sense in the context of the function