Search Unity

Teleportation Only on speffic object

Discussion in 'Scripting' started by CTX, Nov 24, 2014.

?

Collision and Teleportation

  1. Scripts

    0 vote(s)
    0.0%
  2. Edits

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. CTX

    CTX

    Joined:
    Nov 24, 2014
    Posts:
    4
    Hello There

    I am still quite new with scripting. I know the basics of javascript but sadly i dont know yet so many scripts so i would need some help on this one.

    Now i am planning to create a "Teleporter" kind of script that when I (First Person Controller) Collides with it will teleport me to Vector3 (x,y,z)

    Now i have done a script that works and teleports me ( my death script when i fall on terrain i "respawn/teleport" back to beginning). The problem is that this script works with all objects that have a collider.
    Here it is
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. function OnTriggerEnter (other : Collider)
    4. {
    5. transform.position = Vector3(7.619988,1.81378,4.6828);
    6. }
    7. function Update ()
    8. {
    9.  
    10. }
    So what i need is either if i collide with the teleporter it will position me. Or i need to rescript my death script so it only affects for 1 specific colider and not with all coliders.

    Any help is appreciated
     
  2. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    Add a tag on your collider to identify it and compare the tag on the collider in your OnTRiggerEnter().
    If the tag == "Player" then you can teleport back the player.
     
  3. CTX

    CTX

    Joined:
    Nov 24, 2014
    Posts:
    4
    Hey man sorry i forgot to write that i have solved the problem. I will add the script soon so others can see it too
     
  4. laurelhach

    laurelhach

    Joined:
    Dec 1, 2013
    Posts:
    229
    you're welcome!
     
  5. CTX

    CTX

    Joined:
    Nov 24, 2014
    Posts:
    4
    Here
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var TeleportMe = String;
    4. TeleportMe = CharacterController;
    5.  
    6. function OnTriggerEnter (other : Collider){if(other.gameObject.name == "Name") // <-- Name comes here
    7.  
    8. if (TeleportMe == CharacterController)
    9. {
    10. transform.position = Vector3(0,0,0);// <-- Spawn Position comes here
    11. }
    12. }