Sign in to follow this  
Relfos

Help with Eye Movement

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this