Jump to content

[1.17] Render bullet holes on the surface of a block


Recommended Posts

I would like to leave a bullet hole there when my custom projectile hits a block. I can get BlockHitResult with Projectile#onHitBlock,

1. What should I use to render bullet holes? particle? But it points towards the player's camera. Should I create a bullet hole class, save it to a Map and render it directly?

2. No matter how I render, I need data of the angle of the hit surface and its angle. How do I get this?

3. When the bullet hits a block such as a stone, I would like to reflect it instead. After getting the angle of the surface in 2, how do I calculate the reflected vector from it and the delta movement of the bullet?

Please let me know if you have any hints for any of 1, 2 or 3.


For reference, my code is here .

Link to comment
Share on other sites


so I have no idea how rendering works, but I can help you with 3.


You first need to know, that if a ray hits something, it will reflect with the negative angle. So if you have a plane and 0 degrees are exactly a line towards the plane and you shoot a ray with -30 degrees (so a little bit from the left towards the center of the plane) it will reflect with 30 degrees, if you shoot a ray from 0 degrees (so exactly towards the plane) it will reflect with -0 (the same as 0) degrees, if you shoot a ray 70 degrees (so from very right to the middle of the plane) it will reflect with -70 (so to the left)


But now you have a cube and not a plane. If you shoot a ray towards one side of a cube the angle could be 0, 90, 180 or 270 degrees. What you need to do is get the side the arrow hits the block and then subtract 0, 90, 180 or 270 degrees. I'm not sure, but I think north you don't need to subtract (so basically 0). The other sides you need to try. Then, if you have subtracted, you negate the value (this is this -70 to 70, 50 to -50) and add it twice to the rotation of the arrow (not the subtracted). This is your end rotation it will reflect from.


This was everything for a 2D environment, but I think if you know this, you can do the same in a 3D environment like Minecraft


Wow, that was very much

Edited by OutCraft

Sorry if my Posts are weird sometimes, I just try to help and learn as much as I can :D

Also: PLEASE use SPOILERS for logs!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.