lookat problem

Started by
3 comments, last by Pet123 18 years, 1 month ago
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.
Advertisement
umh... maybe this is too obvious
but seeing as how humans can't turn their necks more than about 90degrees to either side...
maybe you need to limit how far your character's neck is allowed to turn?
I'm guessing by 'terribly twisted' you mean the character is moving it head too far and looking... physically uncomforatble...
if the character's neck is twisting too much
don't program it to twist so much

...yup... that should do the trick


ok, seriously though
check and see if what you want the characer to look at is within 'not too twisted' degrees. if it is, then let him look at it.
if it is going to be too far, then turn it off so he stops trying to look at it.
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.

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/

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.


This topic is closed to new replies.

Advertisement