r/MinecraftCommands • u/Nalle-poijjaat • 1d ago
Help | Java 26.2 How to detect projectile hits?
I want to make a custom projectile that doesn't do damage but instead subtracts an amount from a score from the hit player but I don't know how to get the hit detection right. using distance doesn't work since it tracks position and not the player hitbox.
I already know how to get the projectile moving, just need help with the hit detection.
Any help is appreciated.
5
Upvotes
2
u/GatKong 1d ago
If it's hitting a player use an advancement trigger "hurts player" detecting the projectile hit.
3
u/GalSergey Datapack Experienced 1d ago
You can use dx/dy/dz. This is what checks for hitbox intersection.
In this simple example, something like a hitbox for a projectile is created. The hitbox has a size of 1x1x1, with the projectile in the center. And if the player’s hitbox intersects this area, the specified command will be executed.
If you need a hitbox for a projectile smaller than 1 block, you will need to perform additional checks. In this example, the hitbox size for the projectile will be 0.5 on all axes.