- Home /
Rotate object based on FPSCamera
Im building this game that requires the rotation of an object relative to the camera in 3D space. Essentially, i have an object that is the child of an FPS camera which needs to be rotate in front of the camera acting as a third person character. I'm not interested in using mouseX or Mouse y to do this as I'm developing for VR. Help is greatly appreciated!
What have you tried so far? I imagine you've already realized that any rotations onto the object will be relative to the camera's 3 axes and not the scene's.
Which VR / controls are you using?
Answer by blabberbytes · May 04, 2018 at 06:05 PM
I'm programming beginner and someone was helping me and this is what we came up with but it's not working:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeadMotion : MonoBehaviour {
public GameObject headRotationRoot;
public Quaternion rotationFromTheHead;
public Transform tempTransform;
void Start () {
}
// Update is called once per frame
void Update () {
tempTransform = headRotationRoot.transform;
tempTransform.localRotation = headRotationRoot.transform.localRotation;
transform.localRotation = tempTransform.localRotation;
Debug.Log ("headRotationRoot: " + headRotationRoot.transform.localRotation.x );
Debug.Log ("tempTransform: " + tempTransform.localRotation.x );
Debug.Log ("transform: " + transform.rotation.x);
}
}
Your answer
Follow this Question
Related Questions
CCTV behavior rotation issue 2 Answers
Rotate object based on another rotation above a certain threshhold 1 Answer
gameobject stops moving correctly when rotating 1 Answer
Smooth rotation about global axis instead of local axis. 1 Answer
Rotating enemy object to face the player when moving 2 Answers