- Home /
How do I make an object teleport
I have it set so that when an object is triggered, my character turns off, and I want it to teleport back to its starting position, but, I can't seem to find anything that works.
Answer by unity_-v4z-HsChKdEYQ · Aug 03, 2019 at 05:28 PM
by trigger you mean ontrigger function? and turn of meaning set active to false? share some code if i see anything i can help you.. there are a bunch of ways you can teleport.. all depends on the kind of game you are designing.
I have this at the moment:
  private void OnTriggerEnter(Collider other)
         {
             //enter car wall
             wallcar.SetActive(false);
             wall2.SetActive(true);
             //drive able car
             car1.SetActive(true);
             //non-drivve able car
             carfake.SetActive(false);
             //human is fpscontroller
             human.SetActive(false);
         }
 
I want to make it so that when the huma(fpscontroller) turns off, it goes back to its starting position.
i dont understand your script entirely but i guess i dont know the context, you can try setting a bool function to true in the trigger function and in your update function add the code required.. like...
 bool changeposition;
 transform reset;
 void Start()
 { reset.position = human.transform.position}
 void Update()
 {
  if (changeposition)
 { human.transform.position = reset.position;
    //human is fpscontroller
              human.SetActive(false);
 }
 }
 
 
 private void OnTriggerEnter(Collider other)
          {
              //enter car wall
              wallcar.SetActive(false);
              wall2.SetActive(true);
              //drive able car
              car1.SetActive(true);
              //non-drivve able car
              carfake.SetActive(false);
            changeposition = true;
          }
or something like this..
Answer by Okido · Aug 03, 2019 at 06:58 PM
- Declare a variable with the starting position - it's best to have an empty transform in the scene as a spawn point, then you can move/rotate it around whenever you like without worrying about changing the code: 
[SerializeField] Transform _startPos;
(The [SerializeField] keeps the field private but lets you see it in the inspector. You should generally avoid making things public unless you need to)
- Next, in your - onTriggerEnterstatement, you can put this/these:
transform.position = _startPos.transform.position; transform.rotation = _startPos.transform.rotation; //if your character rotates, reset its rotation too  
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                