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:
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.