- Home /
Cannot implicitly convert type `UnityEngine.Vector3' to `UnityEngine.Quaternion'
Hi,
I am currently trying to rotate a object on the y axis in the same time as a different object, but keep running into this error :
Cannot implicitly convert type
UnityEngine.Vector3' to
UnityEngine.Quaternion'
What I have found out online is that I should be using Quaternion.Euler but then run into a simular error with this : Euler' does not exist in the type
UnityEngine.Quaternion'
Code :
using UnityEngine;
using System.Collections;
public class CameraFollow : MonoBehaviour {
public Transform Target;
// Update is called once per frame
void LateUpdate () {
transform.position = new Vector3(Target.position.x, transform.position.y, Target.position.z);
transform.rotation = new Vector3(transform.rotation.x, Target.rotation.y, transform.rotation.z);
}
}
Comment
Best Answer
Answer by HarshadK · Feb 09, 2015 at 10:05 AM
Replace your line:
transform.rotation = new Vector3(transform.rotation.x, Target.rotation.y, transform.rotation.z);
with:
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, Target.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
Your answer
Follow this Question
Related Questions
Rotate gameobject with mouse/touch similar to meshlab or other 3D softwear 1 Answer
Change rotation until it's at 0,0,0 1 Answer
Direction of rotation 0 Answers
Return Object Rotation to x axis is zero 1 Answer
Rotating Rigidbodies 1 Answer