Transform Position Not Moving Object

I’m having a problem changing an object position. I have a teleport system that when the player step in he’s moved to another position. The code is working fine, but won’t change the player object position.
Here is my code:

using UnityEngine;
using System.Collections;
public class Teleport : MonoBehaviour {
    public Vector3 pointA;
    public Vector3 pointB;
    private GameObject thePlayer;
    private Vector3 thePlayerPosition;
    private Vector3 thePlayerLastPosition;
    void Start() {
        thePlayer = GameObject.FindGameObjectWithTag("Player");
    }
    void Update () {
        thePlayerPosition = GridMove.playerPosition;
        thePlayerLastPosition = GridMove.playerlastPosition;
    }
    void OnCollisionStay ( Collision other ) {
        print("Player Has Arrived");
        if (thePlayerPosition == pointA) {
            print("Player is on Teleport A at: " + thePlayerPosition);
            if (thePlayerLastPosition == pointB) {
                return;
            } else {
                TeleportToPosition( pointB );
                GridMove.playerlastPosition = pointA;
            }
        }
        if (thePlayerPosition == pointB) {
            print("Player is on Teleport B at: " + thePlayerPosition);
            if (thePlayerLastPosition != pointA) {
                TeleportToPosition( pointA );
                GridMove.playerlastPosition = pointB;
            } else {
                return;
            }
        }
    }
    void TeleportToPosition ( Vector3 thePlayerDestination ) {
        print("Teleport Player to Position: " + thePlayerDestination);
        thePlayer.transform.position = thePlayerDestination;
    }
      
}

Here is my console output.

Player Has Arrived
Player is on Teleport A at: (2.0, 0.0, 2.0)
Teleport Player to Position: (7.0, 0.0, -2.0)

If i change for example just to test, the player to “this” the block that I step in moves to the position.

void TeleportToPosition ( Vector3 thePlayerDestination ) {
    print("Teleport Player to Position: " + thePlayerDestination);
    this.transform.position = thePlayerDestination;
}

You’re teleporting the player object to pointB then immediately back to pointA then your system gets out of sync.
try else if instead of if in the second case inside OnCollisionStay

   else if (thePlayerPosition == pointB) {

In the first case, after you teleport him to pointB, you update GridMove.playerLastPosition but fail to update thePlayerLastPosition which gets checked immediately after.

So, what I figured out is that you have to disable the object you are trying to change position on, set the position and than enable it.

Player.SetActive(false);
Player.transform.position = new Vector3(PositionX, PositionY, PositionZ);
Player.SetActive(true);

This might be because during gameplay the player or the object you are trying to move is in static mode.

Chirag Shah