Topic category: Help with Minecraft modding (Java Edition)
Helloooo, today I wanted post about how to make a beam attack since there isn't anything really helpful out there that I've seen that shows how to do this correctly and also just because I thought what I made was cool. I decided to post mine to help others out who need it and to also hear some tips to improve the procedure further. This is it right here..... https://www.mediafire.com/file/izp43ghav8ep0pi/BeamCopy.ptpl/file
It uses NBT tags to store where the player is looking in the first interation, so it doesn't move when the player is moving during the attack. To sum it up during each interation it moves the position of the attack forward using look angles and increases the multiplier tag so it keeps increasing the distance each time. Im using local variables so when the next interations start they are back to zero giving the constant beam like look. It does exactly what u see as its hits anything inside the beam not just the end. I also added a break block feature that breaks the blocks according to their hardness and a random variable, so it gives a randomized destruction look. This procedure uses many particles for its look so its not exactly a hd high quality beam, but it works.
This is a video to show what it looks like.... https://i.imgur.com/BG94g9I.mp4 (btw its acts weird on blocks like that because of how I'm nerfing the destruction of it. If u don't care just remove the random variables:) Of course some people might know better ways of achieving this, but this is just what I came up with.
=
That's really impressive! You might want to start the beam a little bit ahead of the player though, it looks kinda hard to see where you're aiming... X)
If you wanted this to be more of a constant, movable thing, there's some stuff you could do with vectors... you could, for example, have a logic variable that tracks whether the player is currently firing the beam, and when it's true, spawn particles at set or random intervals along their look angle vector. If you calculate the magnitude of the vector from the player to the block they're looking at, (find the difference of the x/y/z components, square them, add them, and then take the square root of the sum), you can use that to get a unit vector, which will let you play more with the length of the beam, or change its properties based on the distance. Anyways, looks cool, good work!
I see, thanks for the advice. So, if I can do that I can for example change the amount of dmg it does based on the distance? I was actually wondering how to do this.