How to shoot in the direction the player is looking at?

Started by God_Of_Wood on

Topic category: Help with Minecraft modding (Java Edition)

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to shoot in the direction the player is looking at?

I need to shoot a fireball in the direction the player is looking with the press of a custom key bind, but I can't find the way to do it.

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
For the x/y/z velocity of…
Sat, 11/11/2023 - 16:32

For the x/y/z velocity of the projectile, use the 'x/y/z look-angle vectors' of the player. (There's a seperate x-look angle vector, z-look angle vector, and y look angle vector function.) These essentially get the individual components of the vector, (the arrow the player's looking at), which conveniently can be turned into velocities for your projectile to aim it as you desire.

If you want to increase or decrease the speed of the projectile, multiply each of the vectors, either by a decimal number, (for a slower speed), or a whole number, (for a greater speed.)

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you! For anyone having…
Wed, 11/15/2023 - 13:01

Thank you!

For anyone having the same problem, I also found that MCreator has a 'shoot in player direction' pre-made function.