- Home /
teleport to a object
hey everyone im a beginner in java scripting i just started learning today and im hopeless can somebody please help me and tell me how to teleport from object to object when stepped on.
ThankYou for reading
Answer by aldonaletto · Sep 04, 2011 at 07:11 PM
Create an empty object to be the destination, and adjust its position and rotation. The teleport itself must be a trigger, and have a reference to the destination. You can also add a sound to complete the effect:
var destination: Transform; // drag the destination object here var teleportSound: AudioClip; // set this to the teleport sound, if any
function OnTriggerEnter(col: Collider){ col.transform.position = destination.position; // teleports object col.transform.rotation = destination.rotation; // makes it face the correct side if (teleportSound){ // plays the sound effect at the destination AudioSource.PlayClipAtPoint(teleportSound, destination.position); } }
Answer by unluckyBastard · Sep 04, 2011 at 06:22 PM
var secondObject : Transform; //object you wanna teleport to
function OnTriggerEnter(a : Collider){
if(a.collider.tag == "Teleport"){//we entered the teleporter, make a simple box, change tag to Teleport(case sensitive), box collider set to trigger.
gameObject.transform.position = secondObject.transform.position;//change position to secondObject, whatever that is.
}
}
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Script to teleport player (Beginner here) 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Javascript in Unity, Including iPhone API's (Objective C?) 2 Answers