Script for simple teletransport

Well im trying to make a portal so that the object that collides with the portal moves to the other portal.

Already tried to script it but seem to bump to 1 error.

transform is not a member of System.Type

here is the code

#pragma strict


var target = Transform;



function OnTriggerEnter(col : Collider)

{
    if (col.gameObject.tag == "Player")
    {
       col.transform.position = target.transform.position;
	}
}

some help would be apriciated :slight_smile:

Not sure,
but why dont you try
var target : GameObject;
var targetPos : Vector3;

function Start()
{
targetPos = target.transform.position;
}

function OnTriggerEnter()
col.transform.position = targetPos;

#pragma strict


var target : Transform;

function OnTriggerEnter(col : Collider)

{
    if (col.gameObject.tag == "Player")
    {
       col.transform.position = target.position;
	}
}

make sure you assign a value to target.

I see what you did there.

Thank you! worked and learned a new way!

Thank you all!

There was nothing wrong with your solution tbh. I find renmans redundant. There is no benefit in storing an additional variable for something that is readily available.

The actuality is that storing the GameObject and then referencing it as object.transform.position, actually references it like this: gameObject.GetComponent(Transform).position. Clearly it is quicker on the processor if you store the transform and reference it specifically. However, it does not get that much gain unless you are doing it hundreds if not thousands of times per frame.

You know, this whole time I was under the impression that transform.position was just accessing a member variable (that I presumed was automatically populated during creation), not doing an internal lookup… what a stupid design.

time to rewrite some scripts.

You are correct, transform.position does a property lookup, however, gameObject.transform.position does not. :wink:

Oh right, yes…

So its anything that’s within gameObject thats a lookup?..

ie…
gameObject.transform
gameObject.rigidbody
gameObject.light

You’ve shattered my world :wink: Glad you pointed it out though.