[SOLVED]Super easy quick question

Say I have a gameobject

public var johnSmith : GameObject;

How would I store this object’s local rotation in a Vector3 variable?
I’ve been trying

private var rotVar : Vector3;
rotVar = johnSmith.transform.localRotation;

I keep getting the error

Assets/tester.js(9,29): BCE0022: Cannot convert 'UnityEngine.Quaternion' to 'UnityEngine.Vector3'.

I know I’m prolly missing something really obvious here :stuck_out_tongue:

You could just use the transform var instead of the GameObject One. Instead of a vector3 you could use a float i believe. :smile:

Here is the only Vector3 example i have

var rotationMask = Vector3(0, 1, 0); //which axes to rotate around 
var rotationSpeed = 5.0; //degrees per second 
var rotateAroundObject: Transform; 
///////////////////////////////////////////////////////////////////////////////////
function FixedUpdate() { 
   if (rotateAroundObject) {//If true in the inspector orbit <rotateAroundObject>: 
    transform.RotateAround(rotateAroundObject.transform.position, 
	rotationMask, rotationSpeed * Time.deltaTime); 
   } 
   else {//not set -> rotate around own axis/axes: 
	transform.Rotate(Vector3( 
	rotationMask.x * rotationSpeed * Time.deltaTime, 
	rotationMask.y * rotationSpeed * Time.deltaTime, 
	rotationMask.z * rotationSpeed * Time.deltaTime)); 
   } 
}

Unless your trying to connect every angle with a int or float. That would be easy to do. I recently created a cool analog clock. and had to do just that to get the hands to rotate correctly. :smile:

perhaps do it a different way.

var x = johnSmith.transform.localRotation.x;
var y = johnSmith.transform.localRotation.y;
var z = johnSmith.transform.localRotation.z;

and then combine them.

localrotation = x, y, z;

Noooo idea if it would work, never tried it.

Hmm, well ideally I’d like to store the rotation values as a vector 3 in one variable. I’m using an iTween rotateTo command that can intake Vector3’s.
I could use transform.localRotation.x etc… But that seems like a lot of unnecessary variables.
It’s prolly what I’ll do in the meantime though, thanks for your replies :]

Here’s my code anyway, this is a test script, my plan is to use this for camera movement once I get it right.

testPoint1 and 2 are empty gameObjects parented to the main camera, I’ve been having trouble with the positioning too, the cube (this gameobject) does move but not to the position of the empty’s, it seems to be offset for some reason.
[EDIT]Fixed this offset problem, I had forgotten to also make the Cube a child of the main camera, it was previously a child of an empty group I use for storage.[EDIT]

public var testPoint1 : Transform;
public var testPoint2 : Transform;

private var point1 : Vector3;
private var rot1 : Vector3;
point1 = testPoint1.transform.localPosition;
rot1 = testPoint1.transform.rotation;

private var point2 : Vector3;
private var rot2 : Vector3;
point2 = testPoint2.transform.localPosition;
rot2 = testPoint2.transform.rotation;

public var tweenTime : float = 0.5;
public var tweenDelay : float = 0.01;
private var moveCube : boolean;
moveCube = false;


function Update()
{
	if (Input.GetButtonDown ("View"))
	{
		moveCube = !moveCube;
	}
	if (moveCube == true)
	{
		if (Input.GetButtonDown ("View"))
		{
			iTween.moveTo(this.gameObject, {"position":point1, "time":tweenTime, "transition":"easeOutExpo"});
			iTween.rotateTo(this.gameObject, {"rotation":testPoint1, "time":tweenTime, "delay":tweenDelay, "transition":"easeOutExpo"});

		}
	}
	else
	{
		if (Input.GetButtonDown ("View"))
		{
			iTween.moveTo(this.gameObject, {"position":point2, "time":tweenTime, "transition":"easeInOutBack"});
			iTween.rotateTo(this.gameObject, {"rotation":testPoint2, "time":tweenTime, "delay":tweenDelay,  "transition":"easeInOutBack"});
		}
	}
}

Unity uses quaterions to represent rotations. localRotation.x/y/z will not give you rotations around those axis. That is not what they represent in a Quaterion. I believe you want the following…

rotVar = johnSmith.transform.localRotation.eulerAngles;

Ohh, ahh, thank you that’s the answer I was looking for, so eulerAngles are infact Vector3’s :smile:

Thank you very much :]

Also, if it helps I setup iTween to also be able to take individual axis too so:

iTween.rotateTo(gameObject,{“x”:45});

… is also valid.

And yes use eularAngles and localEularAngles with iTween. Version 2.0 has some more “correct” rotational solutions, I’ll try to get it finished soon… in the meantime you can grab the beta from: Google Code Archive - Long-term storage for Google Code Project Hosting. but I wouldn’t use it in production yet as I’m still changing a lot (the final version won’t even have a JS version)

Oh ok, well I realized shortly after writing the test code my camera won’t need to rotate at all with my current setup, but it’s good to know for future reference :]

Thanks for all your help guys :]