This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

0
Help needed in fixing my eye tracking code
Post Body

I need some feedback on my eye tracking code. Something is wrong either with it or with the eye bones, and I can't figure out what exactly. Firstly, I can only set the direction from the "head" bone and re-use it later for the eye bone, but it is not very precise, I feel. When I uncomment the code in the second pic, the eye goes in a random extreme direction, Secondly, the eyes point lower (3rd pic) than they should (should be on the carrot). Do you spot any mistakes?

func look_at_target(delta):
  if target:
    var targ = target.global_transform.origin
    var target_pos = $skeleton.to_local(targ)

    var bone = $skeleton.find_bone("DEF-neck.001")
    var pose : Transform3D = $skeleton.get_bone_global_rest(bone)
    var direction = (pose.origin - target_pos)
    var look_at_point = pose.origin   direction.normalized()
    var pose_new = pose.looking_at(target_pos, Vector3(0,1,0))
    var angle = (-pose.basis.z).angle_to(-pose_new.basis.z)
    angle = clamp(angle, deg_to_rad(-80), deg_to_rad(80))
    var axis = ((-pose.basis.z).cross(-pose_new.basis.z)).normalized()
    pose = pose.rotated(axis, angle)
    pose = pose.orthonormalized()
    $skeleton.set_bone_pose_rotation(bone, pose.basis)

    bone = $skeleton.find_bone("DEF-eye.L")
    pose = $skeleton.get_bone_global_rest(bone)
    #direction = (pose.origin - target_pos)
    #look_at_point = pose.origin   direction.normalized()
    pose_new = pose.looking_at(target_pos, -pose.basis.y)
    angle = (pose.basis.y).angle_to(pose_new.basis.y)
    angle = clamp(angle, deg_to_rad(-80), deg_to_rad(80))
    axis = ((pose.basis.y).cross(pose_new.basis.y)).normalized()
    pose = pose.rotated(axis, angle)
    pose = pose.orthonormalized()
    $skeleton.set_bone_pose_rotation(bone, pose.basis)

https://preview.redd.it/ioxqwak7llzc1.png?width=697&format=png&auto=webp&s=fe33c9870ac256c37fac4fa90c9f01af248215aa

https://preview.redd.it/jkwr1pk8llzc1.png?width=1045&format=png&auto=webp&s=fff18f2bb163aab380911107ca6f8ec0157d76f9

Author
Account Strength
100%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,691
Link Karma
3,585
Comment Karma
5,865
Profile updated: 1 day ago
Posts updated: 3 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 months ago