When my "Player" teleport it goes back to his last position
Dear Community,
I have been trying to make a teleport Pad(with a trigger) since 2 weeks. What i want to make is : When the player is near to the cube and he presses E, he will be teleported to a new location. But the problem is : when he teleports it goes back to it's last clicked position. SO the question is how do i fix this type of bug, because i am really unfamiliar with this type of bugs.
Here is my Teleport Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleport : MonoBehaviour {
public GameObject ui;
public GameObject objToTP;
public Transform tpLoc;
void Start()
{
ui.SetActive(false);
}
void OnTriggerStay(Collider other)
{
ui.SetActive(true);
if ((other.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.E))
{
objToTP.transform.position = tpLoc.position;
}
}
void OnTriggerExit()
{
ui.SetActive(false);
}
}
and this is how my inspector looks like(the GameObject that i have my teleport script): i also have an empty child into the Teleporter. Thanks for your time.
Answer by Thelegokid4455 · Dec 27, 2019 at 06:54 AM
Make sure that “Auto Sync Transforms” in the Physics section of Project Settings (which can be accessed from Edit) is enabled. If this is not enabled, you’ll find that when your character gets to the Teleport Pad, you’ll be able to see the Teleport Target for a split second but your character will not change position.
source: YT https://www.youtube.com/watch?v=o2M81voNRGc a comment
This was driving me crazy. All the code was correct. All the placements were correct. The screen would flash to where I send the transform, then back to where I was. Clicking on the auto sync just made everything work. Thanks
Answer by Cuttlas-U · Oct 22, 2017 at 05:02 PM
hi; every thing seems fine i think ; can u show me those objects in the hierachy;
Hey,
Thanks for your response
Here is my hierachy: but i think that the problem is in the player movement
hi again; Try this :
objToTP.transform.position = tpLoc.localPosition;
Your answer
Follow this Question
Related Questions
Nested class Lists inspector overlapping bug 1 Answer
RTS camera Controles 0 Answers
Unity game freezes a few seconds after loading scene 2 Answers
Photon - Cannot join same room 1 Answer