What's new

Bug [Unity5] Teleportation System

Z61

Some times our saints are sinners
Retired
Messages
5,528
Reaction score
3,424
(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:

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:
C#:
// 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:
C#:
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.
 

Im Da Best

The next best thing...
Retired
Messages
4,106
Reaction score
3,049
I'm confused as to what you mean by "smooth."

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

Xeren

♦♦♦ God Complex ♦♦♦
Messages
5,689
Reaction score
2,119
It doesn't seem fluid to me, but it could just be me.
I don't see how you can really make teleportation more fluid. While keeping the rotation, you're only moving coordinates.
 

Im Da Best

The next best thing...
Retired
Messages
4,106
Reaction score
3,049
It doesn't seem fluid to me, but it could just be me.
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.
 

MatthewH

Member
Messages
1,612
Reaction score
628
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:
 
Top Bottom