Quantcast
Channel: Answers for "Object rotates with camera"
Viewing all articles
Browse latest Browse all 4

Answer by Clintmcc

$
0
0
I always feel silly but satisfied when I find the answer but its a mistake I had made. I just needed to change the rotate line from Space.World to Space.Self. Thanks Kuba for your contribution. Lookat was the answer to the first problem and Space.self the second problem. Thank you. Here's the final code if anyone else gets stuck. void RotateObject(){ if (Input.GetButton ("Fire2")) { DistanceFromCamera = new Vector3 (0.5f, 0.5f, DistanceHeldFromCamera); rigidbody.gameObject.transform.position = Camera.main.ViewportToWorldPoint (DistanceFromCamera); bool fpsScript; fpsScript = GameObject.Find ("FPSController").GetComponent ().enabled = false; transform.Rotate (0, (Input.GetAxis ("Mouse X") * RotationSpeed * Time.deltaTime), 0, Space.Self); if(!looking){ transform.eulerAngles=new Vector3(0,transform.eulerAngles.y,0); Transform target = Camera.main.transform; transform.LookAt(target, Vector3.up); looking = true; } } else if (Input.GetButtonUp ("Fire2")) { DistanceFromCamera = new Vector3(0.5f,-0.0f,DistanceHeldFromCamera); rigidbody.gameObject.transform.position = Camera.main.ViewportToWorldPoint (DistanceFromCamera); bool fpsScript; fpsScript = GameObject.Find ("FPSController").GetComponent ().enabled = true; looking = false; } }

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images