How to deal damage where the player is looking?

Started by DuckyGK on

Topic category: Help with Minecraft modding (Java Edition)

Joined Sep 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to deal damage where the player is looking?

So I have some code that basicly when the sword is right clicked, it will shoot a sonic boom that deals damage. I got the sonic boom part with all the particles but I cant figure out why the damage is not working. Also, is it possible to only make it a certain range and if so how? Thanks in advance!

 

https://ibb.co/b6vShKF

 

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You'd need to find a unit…
Thu, 10/31/2024 - 16:25

You'd need to find a unit vector to control range. To do that you'd calculate the magnitude of the vector, (find the differences between the player and their target's x/y/z positions, square them, add them together, and then take the square root.) If you divide the x/y/z components by the magnitude, you'll get a 'unit vector,' which has the same direction, but a length of exactly 1, meaning you can multiply it to control the range. (You could also just check if the magnitude exceeds a certain number.) TBH, I imagine you'll have more trouble targeting an entity, I'm pretty sure look angles are mostly just used for getting blocks. 

Joined Sep 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Could you link a picture of…
Sat, 11/02/2024 - 15:26

Could you link a picture of the code, I’m really new to coding and dont understand much

Joined Sep 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also, after I do that, how…
Sat, 11/02/2024 - 15:27

Also, after I do that, how would I deal the damage?