- Home /
My teleport works only with going forward.
Yeah, so literally like a title says, my teleport works ONLY when i'm going forward (2d game so it's more like going "up". (wsad controls) Whenever i'm trying to reach teleport with going down (with s in this scenario) he just reaches teleport and stays there. I'm 100% sure about good tags, names etc. Here's code:
function OnTriggerEnter(col : Collider) {if (col.gameObject.tag == "CaveEnter1") { Debug.Log("Tp to cave"); this.transform.position = teleportLoc[0].transform.position; this.transform.position.y += 1; }if (col.gameObject.tag == "CaveExit1") { Debug.Log("TP to BASE (test1)"); this.transform.position = teleportLoc[1].transform.position; this.transform.position.y += 1; Debug.Log("TP to BASE (test2)");} Debug.Log("TP to BASE (test3)");
}
Funny thing is that, if i'll go to teleport with (example) "s" key (down) i can see in debug log TP to base(test1), tp to base (test2), tp to base(test3), but it does not teleport me.
Any solutions? Please.
you don't need those "this" things in there you know :P also, why are you moving your y up 1? and (I know you said you were sure but i'm going to ask anyways) is your collider a trigger?
$$anonymous$$ight help you to solve the problem if you print out the positions you're teleporting to, to see if maybe the teleporting does work but the locations are messed up. Something like:
function OnTriggerEnter(col : Collider) {
if (col.gameObject.tag == "CaveEnter1") {
Debug.Log("Tp to cave from position " + this.transform.position );
this.transform.position = teleportLoc[0].transform.position;
this.transform.position.y += 1;
}
if (col.gameObject.tag == "CaveExit1") {
Debug.Log("TP to BASE (test1) from position " + this.transform.position);
this.transform.position = teleportLoc[1].transform.position;
this.transform.position.y += 1;
Debug.Log("TP to BASE (test2)");
}
Debug.Log("TP to BASE (test3) position " + this.transform.position);
}
Answer by Ochmar · May 03, 2014 at 09:07 AM
Yeah, my collider is a trigger. I'm moving my y up by 1, becouse when i didnt my Player was teleporting THEN stepping one time forward, now he's like teleporting to y+1 position, then going back to ((y+1)-1) so it looks more like he stays in this pos. (Tried to remove/change it, didnt have ANY impact in program).
Tried to print this, as you said to me, and found funny thing: http://scr.hu/0z5b/u5fr4 It looks like in Debug.Log he is actually changing position, then he's not teleporting at all, camera is not moving or something.
Found that SOMETIMES i can teleport from right side, still dont know why and when.
Your answer