how to make the player teleport 3 blocks forward in the direction the player is look at (2023.3/1.20.1)

Started by CrafterMatt on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to make the player teleport 3 blocks forward in the direction the player is look at (2023.3/1.20.1)

Pls help I'm trying to create a Henry Danger and Danger Force mod and trying to create henry's hyper motility so pls help.

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can use the 'set…
Sat, 09/30/2023 - 02:30

You can use the 'set location' function, (found in entity management), to teleport entities such as the player. From there, you'll need to use the 'get look angle vector' function to get the direction the player is looking at, and teleport them accordingly.

There are a couple ways you could do this. Simpler methods involve just getting the block the player is looking at, (which is its own built in function), and teleporting the player on top of it if there's air available and the block isn't too far away. A more complicated method would be to use the look angle vectors to determine how far to teleport the player on the X, Y, and Z axis. (Look angle vectors range from 1 to -1 on each axis depending on which direction the entity is looking, and can thus be multiplied and then added to the player's current position.) 

The most complicated method, (and the one I prefer for this sort of thing), is to use trig functions to teleport the player based on both the look angle vector and their current velocity. However, this probably involves more math than is really necessary for your purposes.

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Could you pls send a photo…
Sat, 09/30/2023 - 12:16

Could you pls send a photo to make it a bit easier and thanks for the help. You've been my favourite modder. Can't believe this. I played your superior smithing, yor cooking mod and more. They are all good! Excellent job!

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is what I used for warp…
Sat, 09/30/2023 - 15:30

This is what I used for warp-boots that teleport the player forwards. (Keeping in mind this doesn't check if there's actually available space ahead, and will teleport you into a wall if there isn't, for me this is intentional.) The orange blocks all do particles and sound effects, the 'Set Location' block is the only really important one. 

The X look angle vector, (if the player is looking directly east), is positive one, and the z look angle vector, (if the player is looking directly east), is zero. So, if the player teleports while looking east, they teleport (1  8.5) blocks east from their current position, and (0 * 8.5) blocks in the z axis. I didn't configure the Y axis because I only wanted horizontal teleportation, but you could do the same thing there. 

Then, the Dash cooldown thing is just a player variable that goes down every gametick, stopping at zero. The Dash Cooldown has to equal zero for this to execute, just so the player can't spam teleportation.

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks so much
Sun, 10/01/2023 - 13:16

Thanks so much

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Could you also kindly tell…
Sun, 10/01/2023 - 13:35

Could you also kindly tell me how to make a cooldown because it felt like I went 50 blocks forward and it continues if I hold right click

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could create a global…
Sun, 10/01/2023 - 14:05

You could create a global variable for the player, (there's a 'variables' tab in your main workspace), then make a procedure that decreases it by one on player update tick until it equals zero. This way you can check if the variable equals zero before teleporting, and increase it when the player teleports. 

...Of course, if you're just using a handheld item, there's also a built in 'Cooldown item' function in the item procedures tab that'll work just as well, and gives a visual indicator of cooldown.

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry for the asking and…
Mon, 10/02/2023 - 06:19

Sorry for the asking and questions but I do not really know how to code. So could you also send me a picture pls?

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Something like this, where …
Mon, 10/02/2023 - 10:41

Something like this, where 'DashCooldown' is a global, player-persistent variable, which you can assign in the 'variables' tab of your main workspace. Then, put the dash behavior in an 'if' bracket that checks if Dash Cooldown equals zero. 

I highly recommend NorthWestTrees MCreator if you want some decent tutorials. Even if you're using visual code, a good idea of basic principles will be pretty essential if you're going to do anything more advanced.

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks could you help me to…
Wed, 10/04/2023 - 07:41

Thanks could you help me to make a block that if you right click on it it would teleport you to a certain block pls.

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry no entity, when you…
Thu, 10/05/2023 - 06:49

Sorry no entity, when you right click on it, it teleports you to a specific entity

Joined Oct 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hello how can you do to…
Thu, 10/24/2024 - 14:22

hello how can you do to check if there space ahead?

Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You would check if block at…
Thu, 10/24/2024 - 16:15

You would check if block at x y z and x y+1 z is air. Where x y z are the coordinates of the point your trying to teleport to. Eg in the example above it would be:

[(x) + (x look angle vector)*(8.5)] [y] [(z) + (z look angle vector)*(8.5)]