Teleporting!

Well here’s the question: Can it be done?
The answer: YES!

Ignore that first part, here’s my issue:

when I use this thread it works, but only once. I can teleport the character but only one time. I was wondering what you think I should do to fix that?

Here’s the code:

var teleportDistance: float = 10;
var teleportTimeBreak: float = 1;
var characterPrefab: GameObject;
var teleportParticle: GameObject;
var characterTransform: Vector3;


function Update() {
	
	  if(Input.GetButtonUp("Jump")) {
	  		Destroy(gameObject.FindWithTag("characterTeleporter"));
	  		Instantiate(teleportParticle, characterTransform, Quaternion.identity);
	  		Destroy(gameObject.FindWithTag("teleportParticles"));
	  		Instantiate(characterPrefab, gameObject.transform.position + Vector3(0,0,teleportDistance) ,transform.rotation);
	  }

}

Thanks for the help!
-Sam

Destroy(gameObject.FindWithTag(“characterTeleporter”));

looks to me your destrying the teleporter.

Yes. I have a prefab that holds the character. Every time I delete the character it instantiates another copy of it a certain amount of units away. The prefab has the same script. I am not really sure what the issue is, but i don’t think that’s it.

instead of destroying and instantiating it would be easier to just do a transform.position to your point where you want to teleport to

that’s true, but how is that done? Also the current script works with other scripts at the moment so those would have to be changed. If it is possible to fix the current one at the moment I’d prefer that.

its not hard at all just instead of all that destroy and instantiate stuff put transform.position(and pass in the teleporter information here)

okay well this is what I came up with and it’s not working fully. The issue now is that it only moves forward once.

any tips?

var teleportDistance: float = 10;
var teleportTimeBreak: float = 1;
var characterPrefab: GameObject;
var teleportParticle: GameObject;
var characterTransform: Vector3;
var teleportX: float = 0;
var teleportY: float = 0;
var teleportZ: float = 5;
var characterX: float;
var characterY: float;
var characterZ: float;


function Update() {
	characterX = gameObject.transform.position.x;
	characterY = gameObject.transform.position.y;
	characterZ = gameObject.transform.position.z;

	
	  if(Input.GetButtonUp("Jump")) {
	  		transform.position = Vector3(0 + teleportX, 2 + teleportY, 0 + teleportZ);
	  		Destroy(gameObject.FindWithTag("teleportParticles"));
	  Instantiate(teleportParticle, characterPrefab.transform.position, characterPrefab.transform.rotation);
	  }
	  

}

first in transform.position you pass in teleport.x which looks like you dont ever assign. and instead of doing all that characterX Y Z stuff you should just use a vector3.

for some reason it still does the same thing.

I have my code commented above, then yours below. they do the same thing.

/*
var teleportDistance: float = 10;
var teleportTimeBreak: float = 1;
var characterPrefab: GameObject;
var teleportParticle: GameObject;
var characterTransform: Vector3;
var teleportX: float = 0;
var teleportY: float = 0;
var teleportZ: float = 5;
var characterX: float;
var characterY: float;
var characterZ: float;


function Update() {
	characterX = gameObject.transform.position.x;
	characterY = gameObject.transform.position.y;
	characterZ = gameObject.transform.position.z;

	
	  if(Input.GetButtonUp("Jump")) {		
		Instantiate(teleportParticle, characterPrefab.transform.position, characterPrefab.transform.rotation);
		Destroy(gameObject.FindWithTag("teleportParticles"));	
 		transform.position = Vector3(0 + teleportX, 2 + teleportY, 0 + teleportZ);
	  	
	  }
	  

}
*/
var characterPrefab: GameObject;
var teleportParticle: GameObject;
var characterTransform: Vector3;
var teleportX: float = 0;
var teleportY: float = 0;
var teleportZ: float = 5;
var characterX: float;
var characterY: float;
var characterZ: float;


function Update() {
characterX = gameObject.transform.position.x;
characterY = gameObject.transform.position.y;
characterZ = gameObject.transform.position.z;


if(Input.GetButtonUp("Jump")) {
transform.position = Vector3(0 + teleportX, 2 + teleportY, 0 + teleportZ);
Destroy(gameObject.FindWithTag("teleportParticles" ));
Instantiate(teleportParticle, characterPrefab.transform.position, characterPrefab.transform.rotation);
}


}

I figured out that I hadn’t used the variables I created. I just needed to replace the '0’s with characterX Y and Z.

Here’s the working final product :slight_smile: Feel free to screw around with it!

460857–16148–$Teleporting.unitypackage (17.2 KB)

Let me know what you use it for and i’d love to see it in some games! Please give me credit if you use it in a game though. Thanks!

Enjoy :slight_smile:

-Sam