What's new

Bug [Unity5] Teleportation System

Z61

Z61

Some times our saints are sinners
Retired
Programmer Forum Addict Odysseus' Summit
Messages
5,468
Reaction score
3,429
Points
1,042
Sin$
0
(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:
3UubiJZ.gif

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

Im Da Best

The next best thing...
Retired
Scaling the Mountain Bright Idea Mr. Nice Guy
Messages
4,101
Reaction score
3,058
Points
1,170
Sin$
0
I'm confused as to what you mean by "smooth."

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

Xeren

♦♦♦ God Complex ♦♦♦
Legendary Veteran Programmer Modder
Messages
5,668
Reaction score
2,107
Points
795
Sin$
0
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

Im Da Best

The next best thing...
Retired
Scaling the Mountain Bright Idea Mr. Nice Guy
Messages
4,101
Reaction score
3,058
Points
1,170
Sin$
0
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.
 
P

pwfdc

Member
Bright Idea Programmer Experienced Veteran
Messages
1,540
Reaction score
677
Points
465
Sin$
0
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
Login
Register