Camera X Rotation Problems
So I'm trying to create a script where the "weapon" will be in front of the player but when the player looks too far up or down the "weapon" will stop moving. For a visual representation of what I'm trying to do (https://www.youtube.com/watch?v=FkeL74kc0mA).
The problems is that when the player looks down, the "weapon" stops (good) but when the player spins around the "weapon" will reset its self to the normal position (bad).
I've used a Debug.Log to see what's going on and when the player spins the holder will change X rotation from 0.35 to 0.65. I'm a using the Smart First Person Controller asset (https://www.assetstore.unity3d.com/en/#!/content/39505).
Here is the script so far
using UnityEngine;
using System.Collections;
public class Holder : MonoBehaviour {
public GameObject Camera;
private Vector3 eulerRotation;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
eulerRotation = new Vector3(transform.eulerAngles.x, Camera.transform.eulerAngles.y, Camera.transform.eulerAngles.z);
// Low Value High Value 0.65
if (Camera.transform.rotation.x <= 0.35)
{
transform.rotation = Camera.transform.rotation;
transform.position = Camera.transform.position;
}
else
{
transform.rotation = Quaternion.Euler(eulerRotation);
transform.position = Camera.transform.position;
Debug.Log (Camera.transform.rotation.x);
}
}
}
Your answer
Follow this Question
Related Questions
How to convert Quaternions to Euler angles with different order? 0 Answers
Rotate a GameObject a fixed amount on key press struggles. Stops at 180. 1 Answer
Using Local Angles to target enemy object 0 Answers
Problem with Quaternion and Euler Angles 0 Answers
Draw a ray from a gamobject and keep direction of the ray relative to the gameobjects rotation. 1 Answer