how to move the player with a procedure?

Started by Fire32332 on

Topic category: Help with modding (Java Edition)

Last seen on 12:46, 3. Feb 2024
Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to move the player with a procedure?

What procedure should I use to make the player move forward when I right click?

Last seen on 00:55, 28. Mar 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Use the 'attempt to override…
Mon, 01/02/2023 - 17:33

Use the 'attempt to override motion vector of entity' block. It sounds complicated, but it's essentially a block you can use to add momentum in any direction. 

It'll be a little trickier if it's based on the direction the player is looking. If you just wanted to move the player north, for example, you could set the z value to -0.3, (which would always move them north at the same speed), or to the z velocity of the player minus 0.3. (Which will subtract from their current velocity. If they're moving in the opposite direction, this would slow them down instead of immediately moving them north.) 

Luckily, there's two systems you can use to determine the direction of the player. 'Yaw' will give you the direction in degrees; but a more helpful method for velocity is the 'look angle vector,' specifically, the 'z value of look angle vector' and 'x value of look angle vector.' 

If the player is looking directly south, their Z value is 1; if they're looking directly north, their Z value is -1. If they're looking East, their X value is 1, and if they're looking West, their X value is -1. Both the X and the Z value determine direction. Thus

  • North ~ X 0, Z -1
  • South ~ X 0, Z 1
  • East ~ X 1, Z 0
  • West ~ X -1, Z 0
  • And other directions, (such as, say, South West), are a combination South West would be X 0.5, and Z -0.5. 

Conveniently, this system works perfectly with velocity. If you want to accelerate the player in the direction they're looking, you can just attempt to override their velocity to their current velocity, plus the x and z values of their look angle vectors. (You may want to multiply the look angle values by 0.5 or something; a velocity of 1 is pretty fast.) 

Last seen on 16:19, 17. Mar 2023
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
could you show us an example…
Tue, 02/07/2023 - 16:08

could you show us an example of how it would look like?