0
\$\begingroup\$

In my game, I have an Eye Bone that is constantly moving.

I'm trying to make a material attached to the eye (pupil material) move in relation to the Eye bone's transform.

This Script is indeed moving the Material's offset, but it is seemingly ignoring the offsetMultiplier bit. For instance, if I set offsetMultiplier to 0, the material offset never equals 0 but instead keeps exactly following the Bone transform numbers.

What might be the mistake here?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EyeBoneMatOffset : MonoBehaviour
{
    public Transform targetBone;
    public Material mat;
    public float offsetMultiplier = 0.0f; //0 for testing purposes

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        //Create a vector to offset the material
        var offset = new Vector2(targetBone.transform.localRotation.eulerAngles.x * offsetMultiplier, 
                                 targetBone.transform.localRotation.eulerAngles.y * offsetMultiplier);


        //Apply the offset
        mat.mainTextureOffset = offset;
    }
}

Script inspector set up:

enter image description here

Edit:

I'm having issues getting the Eye(Pupil) Material to correctly move with the Eye bone movement.

You can see that when I hit play, the script does get the Eye Material to Initially move, but then it is (visually) frozen instead of moving back and forth. The goal is for it to correctly Eye Track the cube.

As a sidenote, for the Eye Material's X and Y offset, the visually correct range of its pupil movement is -0.45 to +0.45 (X), and -0.45 to -0.45 (Y). So it's weird to me that the X and Y offset of the Eye Materials are shown to be moving within that range (which should be good!), yet are not actually moving visually except for when the game first starts.

enter image description here

enter image description here

\$\endgroup\$
6
  • \$\begingroup\$ Please consider editing your existing questions instead of posting new ones about the same root issue. Can you show us how you've configured this script in the Unity Inspector view? \$\endgroup\$
    – DMGregory
    Commented Jun 6, 2020 at 1:25
  • \$\begingroup\$ Attached is the screenshot of the Script inspector view. Sorry, I will edit in the future. I was concerned nobody would see it if I edited instead of newly posted. \$\endgroup\$
    – m0a
    Commented Jun 6, 2020 at 1:37
  • 1
    \$\begingroup\$ Edits also bump your question, so there's no advantage in reposting to get attention — in fact it is frowned upon. Now, I notice the variable is not zero in your inspector screenshot. What happens if you set it to zero there? \$\endgroup\$
    – DMGregory
    Commented Jun 6, 2020 at 1:39
  • \$\begingroup\$ I did not know the bumping thing; that is very good to know. As for setting in the Inspector, THEN it starts to work. It's not really updating the eye mat offset as expected though; it's more like the mat is stuck in place despite the /bones/ moving properly. So I'm going to be fiddling with this a lot more. \$\endgroup\$
    – m0a
    Commented Jun 6, 2020 at 1:57
  • 1
    \$\begingroup\$ Can you edit your question to explain the difference in motion you're observing? We may be able to help you fix it. \$\endgroup\$
    – DMGregory
    Commented Jun 6, 2020 at 2:03

1 Answer 1

0
\$\begingroup\$

What it was was that the EulerAngles were moving in such tiny increments that they were undetectable. I switched to using the target bone's transform.rotation.x instead, as I am not sure how to correctly use EulerAngles for this issue. If I multiply the EulerAngles by 2, then it still moves the bones by tiny visually undetectable increments of .00001. Really weird.

But- Pseudo-solved by using transform.rotation instead!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Be careful with that. Rotation is a quaternion, not a collection of angles. It's rarely meaningful to take just one component of a quaternion in isolation. \$\endgroup\$
    – DMGregory
    Commented Jun 8, 2020 at 23:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .