Hello All,
I am using the provided FPSController prefab provided with Unity 5 in the character assets.
(I was making my own first person camera script but this provided more options)
I wanted the camera to effect the head bone of my character model.
I want my character models head to tilt where I am moving my camera.
What can I add to the script to do this?
Thank you for your time in advance!
Ok Figured out how to Rotate the neck with the camera (The example below I had to have the X of the camera rotate the Z of the bone)
Put this Script inside the head bone of your character:
using UnityEngine;
using System.Collections;
public class HeadTiltWCamera : MonoBehaviour
{
public Camera cameraRot;
private Vector3 objRot;
// Use this for initialization
void Start()
{
//Only take the x axis rotation
//Bone only uses Z for up and down, camera oddly is using the X for up and down
Vector3 tmp = cameraRot.transform.localEulerAngles;
tmp = cameraRot.transform.localEulerAngles;
tmp.x = 0f;
tmp.y = 0f;
tmp.z = -cameraRot.transform.localEulerAngles.x + 10.0f;
objRot = tmp;
transform.localEulerAngles = objRot;
}
// Update is called once per frame
void Update()
{
}
void LateUpdate()
{
//Only take the x axis rotation
//Bone only uses Z for up and down, camera oddly is using the X for up and down
Vector3 tmp = cameraRot.transform.localEulerAngles;
tmp = cameraRot.transform.localEulerAngles;
tmp.x = 0f;
tmp.y = 0f;
tmp.z = -cameraRot.transform.localEulerAngles.x + 10.0f;
objRot = tmp;
transform.localEulerAngles = objRot;
}
}
There is one problem, The camera will not move its position with the animation because OBVIOUSLY it is not parented to the head.
The problem I have when I parent the camera to the head is the Minimum and Maximum X constraints do not work and the camera will rotate on weird angles.
I suppose I should find a way to just make the neck do what the camera does with the FPS controller and have the camera move with the mouse movements. Or I could figure out why the camera is working oddly when parented to the head.
Well I figured I would post this for anyone that might be interested in this sort of thing.
I once removed the bone from the model and placed it within the first person camera… that worked