# Help with Eye Movement

This topic is 3800 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 on other sites
Could you post updated code, please?

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 32
• 41
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631743
• Total Posts
3001990
×