looking in direction

Hi, I’m working on a little stickman that has eyes.
I want it so that the eyes look at my mouse. I coded that and it worked.
but I want it so that the eyes slowly move and not instantly. I’m currently
using this line of code

bodyParts[1].transform.position = new Vector3(Mathf.Clamp(mousePos.x / xEyeSensitivity, -0.4f * gameObject.transform.localScale.x, 0.4f * gameObject.transform.localScale.x),Mathf.Clamp(mousePos.y / yEyeSensitivity, -0.6f * gameObject.transform.localScale.x, 0.5f * gameObject.transform.localScale.x) -1f,bodyParts[1].transform.position.z);

The Mathf.clamp is so the eyes don’t go too far from his head, the xEyeSensitivity/yEyeSensitivity are there so
the eyes don’t follow my mouse and the * gameObject.transform.localScale.x is there so when I scale up my sttickman things stay in place.

I thought I need to do something with Time.deltaTime but that didn’t work,
does anyone have an idea on how to make the eyes slowly look to the eyes?

You can use Mathf.Lerp.

start position where eyes currently are, target is where you want to look, then some float to specify the rate in which they move.

1 Like

Thanks for the reply!
I got it to work with Mathf.Lerp and it works really smoothly!

1 Like