First of all, you have to know when the player is on impact with the model. You could just check for the distance between the player and the model, or you can use the collision features of 3dgs. Here is an example with distance checking:
action tp1()
{
while(1) //do this calculations all the time the game is running:
{
var distancePlayerAndModel = vec_dist(my.x, player.x); //get distance between player and model with this action
if(distancePlayerAndModel < 200) //if it is less then 200(free to change) do sth.
{
...
}
wait(1);
}
}
Next, you need a way to connect those teleporters. The easiest way would be to just save references to them globally:
ENTITY* entTp1;
ENTITY* entTP2;
action tp1()
{
entTp1 = me;
}
action tp2()
{
entTp2 = me;
}
Now, they can "connect" to each others with the help of their references(entTp1 and entTp2). When you combine both of the above you can change the players position to the other teleport:
action tp1()
{
entTp1 = me;
while(1)
{
var distancePlayerAndModel = vec_dist(my.x, player.x);
if(distancePlayerAndModel < 200)
{
vec_set(player.x, entTp2.x); //now that we can reference the second teleport, set the players position to it.
}
wait(1);
}
}
And the same for the second teleport:
action tp2()
{
entTp2 = me;
while(1)
{
var distancePlayerAndModel = vec_dist(my.x, player.x);
if(distancePlayerAndModel < 200)
{
vec_set(player.x, entTp1.x);
}
wait(1);
}
}
Now you managed to teleport the player to the other teleport. HOWEVER! there is still a problem. The player gets teleported to the other teleport, but then this telport teleports him back immediatly, because the player is in his teleport range. This becomes an infinite loop and the player gets teleported between them all the time. You can fix this by waiting until the player is out of range before teleporting back. You can do this by setting a flag(to say the player just got teleported and before teleporting check if the flag is active:
action tp1()
{
entTp1 = me;
while(1)
{
var distancePlayerAndModel = vec_dist(my.x, player.x);
if(is(my, FLAG3)) //if the player just got telported to this telport:
{
while(distancePlayerAndModel < 200) //do nothing until player gets out of range
{
wait(1);
}
reset(my, FLAG3); //don't forget to reset the flag now
} //and then continue as normal
if(distancePlayerAndModel < 200)
{
vec_set(player.x, entTp2.x);
set(entTp2, FLAG3);
}
wait(1);
}
}
And do the same with the other teleport.
You may have noticed that the code of both actions are pretty redundant. You could fix this by changing the way you reference both portals. Instead of saving references globally, you could save them in the entity it self. Entities have a parent attribute that you could use to reference the other teleport. So why not save the connected teleport in it? Lets try this:
action tp()
{
ENTITY* connectedPortal = my.parent; //see? the entity is now declared inside the tp action and no more in the outside of the action.
}
And now you just need to exchange the variables in our latest tp action:
action tp()
{
ENTITY* connectedPortal = my.parent;
while(1)
{
var distancePlayerAndModel = vec_dist(my.x, player.x);
if(is(my, FLAG3))
{
while(distancePlayerAndModel < 200)
{
wait(1);
}
reset(my, FLAG3);
}
if(distancePlayerAndModel < 200)
{
vec_set(player.x, connectedPortal.x);
set(connectedPortal, FLAG3);
}
wait(1);
}
}
Thats all the code for both teleports! You can now just set the action to both of them in WED. To connect them, you just set the parent in WED to the other teleport(don't forget to do this with both too).
I did not try out the code, so there might be a lot of mistakes ^^