- Home /
Question by
daniells1004 · Dec 30, 2021 at 06:58 PM ·
scripting problemscripting beginnerik
How can I make the head turn with the camera?
Hello fellow developers, So in many games theres a system where the head turns to whatever side you look at, I really like that effect and want to implement it with the character I have. I couldnt find any source of how to achieve that so I decided to just ask it here.. Im starting to get into Unity more now so apologies for any 'rookie' mistakes.. This is my code so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeadIKManager : MonoBehaviour
{
public GameObject Head;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Camera.main.transform.localRotation.y < 0.5f && Camera.main.transform.localRotation.y > -0.5f)
{
Head.transform.rotation = Camera.main.transform.rotation;
}
}
}
Ive tried a different way of IK animator type of thing from a video I found where the head is looking at an object and it worked for me as well, but I want the head to look to the direction of the camera, not an object.
Comment