- Home /
Can't change player's position
I have a simple script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TeleportBack : MonoBehaviour
{
public Vector3 teleportPosition;
void OnTriggerStay(Collider other){
if(other.gameObject.tag == "Player") {
other.transform.Translate(teleportPosition, Space.World);
Debug.Log("Teleported Player back");
}
}
}
It works and all, but the StandardAssets FPSController only gets teleported "visually" to the position while on the collider trigger(in editor the coordinates also change only visually and in game the camera stays on the "visual" coordinates). When walking out of the trigger(with the physical coordinates) player visually goes back to his physical coordinates. Any ideas?
A little more details to any of those who'd like to help. The script spams the Debug.Log infinitely while the player is on the trigger with his physical/real coordinates.
Answer by GreatCorn · Apr 09, 2019 at 08:31 PM
Figured out I could try disabling the CharacterController before the Translate function and then enable it right after that. Worked for now.
Thank you! I was stuck on figuring stuff with teleporting the player for about 2 hours and then I stumbled upon your post.
Do you know why disabling the character controller works?
Thanks a bunch, that dug me out of my hole. I was working on a Save/Load function and couldn't understand why my properly saved position was not updating the character. Just had to disable the character controller first
cc.enabled = false;
cc.transform.position = new Vector3(position[0] , position[1] , position[2]);
cc.enabled = true;
Thank you so much! I spent a whole day trying to move a player to a checkpoint after they're dead, but it seldom failed so it respawned in the same position they died. After reading this, I got it to work by first diabling the CharacterController, moving the player's gameobject and the re-enabling the CharacterController.
Thanks!
Answer by NiGodfrin · Sep 08, 2020 at 10:44 PM
Hi, I'm a little bit later but I think it's just because Unity don't authorize weird position transition like teleportation by default. What you can simply do, is going to Player Setting -> Physics and enable Auto Sync Transforms.
Answer by cs120319992 · Apr 11, 2019 at 09:24 AM
other.transform.position = teleportPosition;
I have already tried that. Without doing stuff to the CharacterContoller nothing worked for me.
Your answer
![](https://koobas.hobune.stream/wayback/20220612195141im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I want to find a transform when an object is instantiated 2 Answers
Player Spawning Network issue 1 Answer
Setting Player positioning on a different loaded scene with Dont Destroy On Load attached. 0 Answers
Multiplayer Changing Who "Owns" a Script? 0 Answers
How do I make an object teleport 2 Answers