Lesson 6

Let's make a teleportation device

Here is our task list:

First code the teleporter platform.

Add input to the teleporter function so it can be placed near the player, and a second up in the air.

Start a loop that contains the condition if the player steps on one teleporter it changes their position to the other teleporter.

Things to notice:

  • Line 10: The teleporter function is given information along with the function. That is called passing an argument to the function. This is very important, because it lets you use the same function in different ways.
  • Line 8: We can change the Y position of the pos2 Vec3 variable by itself! That will make the second teleporter be up in the air while staying at the same X and Z position.
  • Line 17-18: The teleporter function is called twice, with two different positions as arguments. The second time a teleporter is created up in the air! Look up!

Now we start a game loop with a condition that changes the player's position to the other teleporter.

Things to notice:

  • Line 22: After calling the teleporter function twice we move the player back so it doesn't teleport immediately.
  • Line 23: Start a timer so we can limit the while loop to run for a specific amount of time.
  • Line 24: The while loop will run for 60 seconds.
  • Line 25-29: Each loop get the player's tile position. If it is the same as pos1 set earlier, move the player to pos2 (and two blocks back), and do the same for pos2.

Lesson 6 is done! Don't forget to answer questions for Lesson 6 in MyHewitt.