How to deal damage where the player is looking?

Started by DuckyGK on

Topic category: Help with Minecraft modding (Java Edition)

Active 6 months ago
Joined Sep 2024
Points:
84

User statistics:

  • Modifications: 0
  • Forum topics: 3
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 6
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

 

Active 1 month ago
Joined May 2022
Points:
1297

User statistics:

  • Modifications: 15
  • Forum topics: 25
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 1143
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. 

Active 6 months ago
Joined Sep 2024
Points:
84

User statistics:

  • Modifications: 0
  • Forum topics: 3
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 6
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

Active 6 months ago
Joined Sep 2024
Points:
84

User statistics:

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

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