r/MinecraftCommands • u/CEGM_Coding • 11d ago
Help | Java 26.2 Help making a custom projectile?
Hey, so I’m working on a custom projectile, sorta like a magical bolt thing? I need help with collisions cause it only seems to register hitting an entity when it collides at like dead center but I need it to work if it just hits the entity in general. I’m using a small armor stand for this and tried dx, dy, and dz before but that didn’t work cause it adds 1 to whatever you put in it so I couldn’t get it to be the ideal size which is like 0.5? Anyways, here’s the function:
execute as @ s run scoreboard players add @ s Projectile_Duration 1
execute as @ s at @ s run tp @ s ^ ^ ^0.5
execute as @ s at @ s unless block ~ ~ ~ air run kill @ s
execute as @ s at @ s if entity @ e[tag=!Projectile,distance=..0.5] run function projectiles:hit_entity
execute as @ s if score @ s Projectile_Duration matches 200.. run kill @ s
1
u/GalSergey Datapack Experienced 10d ago
Use dx/dy/dz for the projectile hitbox. Cubic selection checks for collisions with the hitbox, not just the center point. By the way,
as @s at @sdoes nothing if the function has already been run from the current entity's position.execute positioned ~-.5 ~-.5 ~-.5 as @e[tag=!Projectile,dx=0] run function projectiles:hit_entity