Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, juanex, Grant), 1,018 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
teleport from model 1 to 2 ande vica versa #414076
12/22/12 11:41
12/22/12 11:41
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
I remember this discussed somewhere but i can't find it.

I need my player to teleport on impact to a certain model in
my level. If player has impact on that model it gets teleported back to the first place. Basicly i would need 2 models to place that the player can use to teleport fore and backwards.

Can any one point me in the good direction laugh


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: teleport from model 1 to 2 ande vica versa [Re: Realspawn] #414085
12/22/12 15:45
12/22/12 15:45
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
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:
Code:
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:

Code:
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:

Code:
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:
Code:
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:
Code:
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:

Code:
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:
Code:
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 ^^

Re: teleport from model 1 to 2 ande vica versa [Re: krial057] #414086
12/22/12 15:52
12/22/12 15:52
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
wow that's a long story i will toy with it and see if i can get it all to work laugh

thx


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1