Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Teleportation 3d

Discussion in 'Scripting' started by TheReaLsQuaLL, May 4, 2020.

  1. TheReaLsQuaLL

    TheReaLsQuaLL

    Joined:
    Apr 10, 2020
    Posts:
    29
    Hi i am trying to do a Teleportation script like Nightcrawler from Marvel.When i click i can teleport anywhere within range,but i can't find any tutorials About that i can only find Teleportation with Teleportation pafs or Portal gun.Any idea to help me?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    The only thing you need to do to teleport an object in Unity is simply this:
    Code (CSharp):
    1. Vector3 teleportDestination = /* <your teleport destination here> */;
    2.  
    3. transform.position = teleportDestination;
    Of course you might want to have a cool visual effect happen at the same time! I would look into Particle Systems or Visual Effects in Unity to achieve that:

    https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@8.1/manual/index.html
     
    TheReaLsQuaLL likes this.
  3. TheReaLsQuaLL

    TheReaLsQuaLL

    Joined:
    Apr 10, 2020
    Posts:
    29

    Thanks for the answer but i want it like a circle that with my mouse i can select where to teleport.This Scene will be 3rd Person.There was a game named Jumper on ps2 something like that.
     
  4. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    Use a Raycast from your camera position:
    https://docs.unity3d.com/Manual/CameraRays.html

    You will get the position on the ground as a result. Make your validation afterwards, like a
    Code (CSharp):
    1. Vector3.Distance(player.transform.position, hit.transform)
    to see if the teleport was in range
     
    TheReaLsQuaLL likes this.
  5. TheReaLsQuaLL

    TheReaLsQuaLL

    Joined:
    Apr 10, 2020
    Posts:
    29
    Thanks man i will try as soon as i can.
     
  6. Noblauch

    Noblauch

    Joined:
    May 23, 2017
    Posts:
    256
    It will be insane, believe me!
     
  7. JTAGames

    JTAGames

    Joined:
    Mar 7, 2019
    Posts:
    13


    Is a tutorial we made and I'm pretty sure it's exactly what you're looking for. You can add the range of teleportation in an if statement.