2D portal recreation, portals keep teleporting player between them without letting the player move away
Hey,
I am recreating portal in 2D for a small project and the teleportaion works, the only problem is the player teleports tn the other portal and then straight back again, this keeps happening until the game breaks and the player falls through the floor.
Is there a way that I can move the player away from the portal with some speed to stop the constant teleporting from happening?
Would I have to know what wall the portal has been placed on to move the player away from it in the opposite direction?
public class StepThroughPortal : MonoBehaviour {
public GameObject otherPortal;
void OnTriggerEnter2D(Collider2D other){
Debug.Log ("Hit the Portal");
if (other.tag == "Player") {
other.transform.position = otherPortal.transform.position + otherPortal.transform.forward*2;
}
}
}
Any help at all would be greatly apprecitaed
Cheers
Couldn't you simply make the portal colliders smaller? Or spawn the player a little further away from them?
Answer by AntikytheraMachines · Feb 07, 2016 at 08:46 AM
could each portal have two parts? so entrance A -> exit B then for the player to trigger B -> A they would have to move to entrance B. as it is now you have entrance A and exit A co-located. as are Entrance B and Exit B.
i'm picturing a mirror / door type portal where the player enters one side and exits the other. or perhaps a set of teleporter pads where the player stands on the entrance pad and arrives on the exit pad.
perhaps some sort of switch where the player has to hit the switch to teleport. so when they arrive, unless they immediately hit the switch they stay at the new location. or a timer so they cant reuse the teleport for 10 seconds after arrival.
Your answer
Follow this Question
Related Questions
how to make a 2D player teleport to certain X and Y when they enter a trigger 2 Answers
I want to make a weapon follow the player after i instatiate the weaponinto the game. 1 Answer
Having a couple of problems regarding 2D Movement. 1 Answer
Making a list of images within a scrollrect generated from prefabs tappable/clickable 1 Answer
Drag 2D Sprite by Touch 1 Answer