Search Unity

New to Unity trying to teleport FPS to a new location

Discussion in 'Getting Started' started by mishelbi, Jan 23, 2019.

  1. mishelbi

    mishelbi

    Joined:
    Jan 20, 2019
    Posts:
    8
    I am new to Unity. Totally green here. I'm trying what should be a simple transport of my fps to a new location when it touches a capsule. The capsule is marked "Is Trigger" and the script is:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Portal : MonoBehaviour
    6. {
    7.     // Start is called before the first frame update
    8.     void Start()
    9.     {
    10.         Debug.Log("Portal Stone created");
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update()
    15.     {
    16.        
    17.     }
    18.  
    19.     void OnTriggerEnter(Collider Col)
    20.     {
    21.        
    22.         Debug.Log("You touched the stone");
    23.  
    24.         // takes the object which collided and applies a transform
    25.         // to send them back to the start of my level
    26.         Debug.Log("before transform");
    27.        
    28.            
    29.             Col.transform.position = new Vector3(0,0.0F,0);
    30.             print(transform.position.x);
    31.             print(transform.position.y);
    32.             print(transform.position.z);
    33.             Debug.Log(Col.name);
    34.             Debug.Log(Col.tag);
    35.  
    36.  
    37.  
    38.  
    39.     }
    40.  
    41.    
    42.  
    43. }
    I get the proper coordinates in the print messages and it says its FPS and Player but my player doesn't move.

    What am I doing wrong?
     
  2. You're setting the "other" collider's position (presumably the player or anything which can make contact with the portal).
    But then you print the portal's position.

    Your portal is at the 0,0,0 position as well? Because you're sending the player to the same position in your 29th line. So I don't understand what you're trying to achieve.

    Also, depending on the method you move your player (if it's a Character Controller for example), you may not want to move your player by its transform. But I won't expand on it, read the manual how to move a physics body and how to move a Character Controller if you use it.
     
  3. mishelbi

    mishelbi

    Joined:
    Jan 20, 2019
    Posts:
    8
    I'm trying to send the character to position 0,0.0. The portal is not at that position. The character is a FPS.