How to make an entity teleport you to another?



  • I'm trying to do my own portal gun with only command blocks, and it is going pretty well.
    But, the thing is, I can't make the teleport system work correctly.
    What I'm trying to do is if you're in a certain distance from the armor stand with the name "blue", you're teleported to 2 blocks in front of the armor stand with the name "orange" and also make the same but reverse (orange to blue). Everything I tried either didn't work, or made so you're teleported exactly where the armor stand is, making you stuck in a TP loop.

    How could I make it work correctly?



  • To do a teleporter, we need to add some sort of cooldown so that it won't activate on the other side; Or you could do what you suggest which is put the player on a place that it wouldn't trigger the teleport.

    We will have two cooldown tags, refering to each armorstand. Our steps will be:


    • If the player is close enough and doesn't have the tag for that armor_stand:

      1. Add the cooldown tag of the other armor_stand
      2. Telport to the other armor_stand
    • If the player is far enough of said armor_stand, remove their own cooldown tag.


    Which translates to:

    execute at @e[type=minecraft:armor_stand,tag=orange] as @a[distance=..1] unless entity @s[tag=ignore_orange] run tag @s add ignore_blue
    execute at @e[type=minecraft:armor_stand,tag=orange] as @a[distance=..1] unless entity @s[tag=ignore_orange] run tp @s @e[limit=1,type=armor_stand,tag=blue]
    execute at @e[type=minecraft:armor_stand,tag=orange] as @a[tag=ignore_orange, distance=1..] run tag @s remove ignore_orange
    

    execute at @e[type=minecraft:armor_stand,tag=blue] as @a[distance=..1] unless entity @s[tag=ignore_blue] run tag @s add ignore_orange
    execute at @e[type=minecraft:armor_stand,tag=blue] as @a[distance=..1] unless entity @s[tag=ignore_blue] run tp @s @e[limit=1,type=armor_stand,tag=orange]
    execute at @e[type=minecraft:armor_stand,tag=blue] as @a[tag=ignore_blue, distance=1..] run tag @s remove ignore_blue




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2