I'm trying to make a portal on which if my player enters, he gets transported to a certain position elsewhere.
Right now I'm using the following logic.
if(tile.tag=="portal")
{
int x = System.Convert.ToInt32(portaldest.transform.position.x);
int y = System.Convert.ToInt32(portaldest.transform.position.y+1);
int z = System.Convert.ToInt32(portaldest.transform.position.z);
player.transform.position = new Vector3 (x,y,z);
print (player.transform.position);
}
This logic seems to be correct, and should work perfectly. The issue I'm getting here is, say my portal destination is the spot (0,0,-3), the player gets moved to a different position which is (0, 0, 3.4) which shouldn't happen. As I even made the position to be an int position.
edit: When printing, it shows the position as (0.0,0.0,3.0) so it should be working. :/
edit2: Just some things you might want to know. The player is a rigid body, use gravity is on, freeze x and z are on. Collision detection is continuous. If I remove the freeze on x and z I can't enter the portal, and if I remove gravity, it's y axis increases to infinity after entering the portal.
↧