Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

lookat problem

Started by Pet123 3 replies 700+ views
Original Post
Pet123
Pet123
hi there we have a character in game, to make it more real, we're going to control its head directly so it will be able to look at anything we want it to, its skined mesh and the bone we pick to be controled is 'head bone', the bone itself is on hierarchy. its easy to make it look at whatever we want it to (for example the camera), but the problem is its often rotated too much so the final character's head is terribly twisted while staring at me (or the camera). so i want to know how to solve this problem? is IK needed? for now my computation for the lookat rotation is : forward = target_pos - head_pos; side = cross(forward, vector3(0, 1, 0)); up = cross(side, forward); compose_rotation_matrix(side, forward, up); thanks.
JBourrie
JBourrie
What I have done in the past is create an angle constraint. When you go to look at a point:

- Vector v = point - headposition
- Vector f = the direction that the character is facing
Both normalized.

if angle between v and f is greater than constraint:
Look forward instead.

That way, if he can't see the point, he will not twist his neck trying to look at it, and instead will look forward.
Pet123
Pet123
thanks for the replies -- i have found the reason why it twisted that way : i calculated the rotation in wrong space. but i noticed another flaw : sometimes the head turns in wrong direction though its final lookat direction is correct. for now i have no idea how to always rotate it correctly, im using quaternion slerp, anyway i'll try to find cure for this on my own first.
p.s. i still think its not enough by rotating its head only, it looks fake sometimes, maybe i should try IK to make it more realistic.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.