Bug [Unity5] Teleportation System

Discussion in 'Game Development' started by Z61, Apr 13, 2015 with 5 replies and 598 views.

  1. Z61

    Z61 Some times our saints are sinners Retired

    Messages:
    5,520
    Ratings:
    3,061
    (Not really a bug)
    I'm working on prototyping a simple teleportation system and it's working decently well, but I want to see if I can make it more smooth.

    Image of it in action:
    [​IMG]
    Current layout:
    Parent Teleport Object(Holds two teleporters or more)
    Teleporter - can be entrance or exit
    Teleporter - can be entrance or exit
    When the user collides with either it sends them to that other one and they can't teleport again for a little while.

    Teleporter Object Code:
    Code:
    // The A child teleporter (actual object the user collides with.
      void OnTriggerEnter(Collider collision) {
         if (collision.gameObject.tag == "Player") {
           //Debug.Log (type.ToString() + " collided with player.");
           if (type == TeleporterType.Mixed || type == TeleporterType.Entrance) {
             teleportToPartner();
           }
         }
       }
       void teleportToPartner() {
         SendMessageUpwards ("doTeleporter", partner);
       }
    
    Parent Object Code:
    Code:
    public class TeleportParentController : MonoBehaviour {
    
       public float timeSinceTeleported = 0f;
       GameObject Player;
       // Use this for initialization
       void Start () {
         Player = GameObject.FindGameObjectWithTag ("Player");
       }
       
       // Update is called once per frame
       void Update () {
       
       }
       void FixedUpdate() {
         timeSinceTeleported += Time.smoothDeltaTime;
       }
       void doTeleporter(GameObject location) {
         if (timeSinceTeleported > 0.4) {
           Vector3 pos = location.transform.position;
           Player.transform.position = new Vector3 (pos.x, pos.y, pos.z );
           timeSinceTeleported = 0;
         }
       }
    }
    
    
    If you can think of any ways to smooth it, let me know.
     
  2. Im Da Best

    Im Da Best The next best thing... Retired

    Messages:
    4,089
    Ratings:
    2,956
    I'm confused as to what you mean by "smooth."

    To be honest, I think it looks really good right now.
     
  3. OP
    Z61

    Z61 Some times our saints are sinners Retired

    Messages:
    5,520
    Ratings:
    3,061
    It doesn't seem fluid to me, but it could just be me.
     
  4. Xeren

    Xeren ♦♦♦ God Complex ♦♦♦

    Messages:
    5,678
    Ratings:
    1,889
    I don't see how you can really make teleportation more fluid. While keeping the rotation, you're only moving coordinates.
     
  5. Im Da Best

    Im Da Best The next best thing... Retired

    Messages:
    4,089
    Ratings:
    2,956
    The way you've got it set up is how it's done in a variety of games.

    If you wanted to get fancy with it, you could add an animation for when you teleport and a delay in before you assign a new position.

    Although that all depends on how you plan on applying this to the game.
     
    • Like Like x 1
  6. MatthewH

    MatthewH Member

    Messages:
    1,612
    Ratings:
    615
    Transforming the position is teleportation. So as a base you're teleportation system is working.
    How would you make it smooth? You could at a coroutine as a timer and some animations for particle effect. So when you enter on (OnEnter) you run a particle that explodes (giving the effect of the model disintegrating into thin air) and reverse the animation and have it implode at the new spawn point giving the the effect of the body coming back together.

    Or you could go portal style and only "teleport" the part of the model that's touching, however I've personally never succeeded with this style in Unity. :banghead::frown::cry:
     
    • Like Like x 1

Share This Page