Vector3 and transform.rotation?


I’m trying to do a simple reset players position, I’ve got it all working apart from the players rotation. I’m trying to use a vector3 but I keep getting this error “OutOfZone.cs(24,34): error CS0029: Cannot implicitly convert type UnityEngine.Vector3' to UnityEngine.Quaternion’”

public class OutOfZone : MonoBehaviour {
	public Transform Player;
	public Vector3 coOrds;
	public Vector3 view;
	public AudioClip fallSound;
	public AudioClip goBackSound;
	void OnTriggerEnter (Collider col) 
	IEnumerator outZone()
		yield return new WaitForSeconds(2);
		Player.transform.position = coOrds;
		Player.transform.rotation = view;
		yield return new WaitForSeconds(1);

What do I use to get this to work?

The problem is pretty much exactly what the error says. :slight_smile: In this line:

Player.transform.rotation = view;

You are attempting to set the rotation to the variable view, but view is of type Vector3, and the rotation of a Transform is of type Quaternion. Those types are incompatible - you can’t set it like that. You have to either set the rotation using a Quaternion you create with the Quaternion constructor directly, or by creating a quaternion using one of the static methods in class Quaternion.

For example, since you’re storing view as a Vector3, maybe I can assume you’re actually storing the degrees of rotation around x, y and z in view.x, view.y and view.z? In that case, you can set your rotation like this:

Player.transform.rotation = Quaternion.Euler(view.x, view.y, view.z);

i have tried
eulars is vector3 type.
transform.rotation = Quaternion.Euler (eulars.x, eulars.y, eulars.z);
but it gives error
Assertion failed on expression: ‘CompareApproximately(SqrMagnitude(result), 1.0F)’
UnityEngine.Quaternion:Euler(Single, Single, Single).

Please help me out.