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
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
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);
}
}
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.
}
}