Help with Eye Movement

Started by
2 comments, last by MaR_dev 16 years, 2 months ago
In my game I'm trying to animate the character eyes, similar to what happens in Zelda:Wind Waker. Basically, I assign a "Target" point, and the character should move their eyes in that point direction, unless the point is not visible (behind their head, for example). My technique consists of rendering first opaque white eyes, and the calculate the texture coords displacement to render the iris/pupils. The calculations I'm currently doing are those, where Source is a point somewhere between the character eyes, Direction is a normal Function GetEyeToTarget(Target, Source, Direction:LVector):LVector; Begin // Calculate direction between source and target Result:=VectorSubtract(Target, Source); Result:=VectorNormalize(Result); // Check if target is not visible If VectorDot(Result, Direction)<0 Then Begin Result.X:=0; Result.Y:=0; End Else Begin // Scale the texture coords offset Result:=VectorScale(Result, 0.075); End; End; However, this function doesnt work as it should, half of the time. Sometimes the character looks where it should, sometimes look in the opposite direction it should, like in this image. The blue arrow is the eye "Direction" vector, and the red one is the calculated normal between "Source" and "Target", properly rescaled. I think the problem is that I only use the X and Y coords of the displacement vector, since I add it to the texture Coords UV vector. So, I'm discard the Z value of the direction, and I'm not too good at math, how can I fix this?
Advertisement
I dont know if I understand your method correctly, but I think you need to rotate target vector to your pupil space, where x,y are same as u,v and z is a direction character is facing. Thus if you happen to not to use scale, rotate direction vector with inverse of your character rotation.

Ok, I changed it.
Now I calculate the direction vector from the eye Position, and the target Position, and normalize it.
Then I rotate it by the inverse transform of the object.

It works better now, but the X result is reversed for some input positions, almost half of time actually...
Could you post updated code, please?

This topic is closed to new replies.

Advertisement