Getting Transform info of objects

So I’m pretty new to scripting, and teaching myself about Lerping today. I have a script that moves an object from one position/rotation to another. But I want to understand how to get the current Transform info from the object that the script is a component of and the Transform of another object to be used as the target of the Lerp. Currently my simple lerping script just sends from a specific position/rotation to another:

var Begin_Rotation = Vector3(0,261.2132,349.1754);
var End_Rotation = Vector3(8.782372,269.7128,97.0043);
var timer = 0.0;
var speed = 0.5;

var Begin_Position = Vector3(-4.518043, 0.9568615, 1.280597e-05);
var End_Position = Vector3(3.576072, 0.8233643, -1.32454e-05);

    function Update(){
		
		timer += Time.deltaTime;

		transform.eulerAngles = Vector3.Lerp (Begin_Rotation, End_Rotation, timer*speed);
    	transform.position = Vector3.Lerp(Begin_Position, End_Position, timer*speed);
        
    }

Can someone explain the basics of getting objects’ Transform info?

3 Answers

3

It’s simply GameObject.transform.position. It is stored as a Vector3, and is null if your object has no transform component.

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.html

Who is upvoting these lies? transform is NOT a Vector3! And EVERY GAMEOBJECT has a TRANSFORM.

Flavius, my mistake. I meant to say GameObject.transform.position, cool down :)

transform.position

You are already doing it. ‘transform’ is the Transform of the current gameObject.

Thanks, fellas. That worked. Embarrassingly simple, in retrospect. Boy do I have a lot to learn.

var destinationObject: GameObject;

var timer = 0.0;
var speed = 0.5;

var Begin_Rotation = transform.eulerAngles;
var End_Rotation = destinationObject.transform.eulerAngles;
var Begin_Position = transform.position;
var End_Position = destinationObject.transform.position;

    function Update(){
		
		timer += Time.deltaTime;

		transform.eulerAngles = Vector3.Lerp (Begin_Rotation, End_Rotation, timer*speed);
    	transform.position = Vector3.Lerp(Begin_Position, End_Position, timer*speed);     
    }