- Home /
How to transform position?
Can someone show me the script to teleport an object? I mean to transport it to another position?
here is what I did :
var player = gameobject.find("Cam1");
funtcion update () { If input.getkeydown("e") transform.position = var player (0,0,0 )
well it seems cr** to me.
Im realy need help on this one guys, please.
You really need to take care with spelling and capitalisation of function names. Take a look at $$anonymous$$ike's answer for how to fix your problems, but as an example, it's '`GameObject.Find()`' and '`Input.Get$$anonymous$$eyDown()`'. Check the Script Reference if you're unsure.
Answer by Mike 3 · Feb 15, 2011 at 01:17 PM
You want something along the lines of this:
var player = GameObject.Find("Cam1");
function Update () {
if (input.GetKeyDown(KeyCode.E))
{
//i'm not sure what you were trying to do here, so i'll add in 3 examples of what you could do
//bring the object to the player
transform.position = player.transform.position;
//bring the player to the object
player.transform.position = transform.position;
//move the player to 0,0,0 - you can also use Vector3.zero instead of Vector3(0,0,0)
player.transform.position = Vector3(0,0,0);
}
}
Edit:
function OnTriggerStay(other : Collider) {
if (Input.GetKey(KeyCode.E))
{
var player = GameObject.Find("First Person Controller");
player.transform.position = Vector3(-20391,10598,-25495);
}
}
IT WOR$$anonymous$$S!! THAN$$anonymous$$ YOU DUDE!!
Seriously! Three days I've been asking how to do this! Three days I've been trying different things... for this simple piece of code...
Anyway thanks. By the way, I've got to set the trigger button on for the mesh collider. Is there a way to make the mesh being a true collider because with this set on the mesh doesnt collide anymore with the fps controller.
Or is it better that I make an other "invisible" object to put this script on?
If a meshcollider isn't working, you could try click the box for making the mesh collider convex. If that isn't working, there could be something else wrong, but otherwise sure, add another object with colliders
thank you, everything is fine anyway.
You're saving me.
Answer by Moltvatch · Feb 15, 2011 at 01:29 PM
Here is what I did :
function Update () { var player = GameObject.Find("First Person Controller");
}
function OnTriggerStay(other : Collider) { if (Input.GetKeyDown(KeyCode.E)) { //move the player to 0,0,0 - you can also use Vector3.zero instead of Vector3(0,0,0) player.transform.position = Vector3(-20391,10598,-25495);
}
It tells me that player is unknown. "unknown identifier player"