# [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 .

##### Share on other sites

Hi,

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
Spelling

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

Also: PLEASE use SPOILERS for logs!

## 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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

• ### Posts

• Im trying to play a modded 1.7.10 minecraft server, but when i try joining, it says Connecting to server, and then it goes to Logging in. Even after i wait a while it stays on that screen, i waited maybe an hour for it to work and it did not. The game is not frozen because i can press Cancel and it goes back to normal, and singleplayer works fine, so i dont know what to do. I even tried using a mod called Lan UPNP, which lets you host servers from singleplayer using the hosts ip address, and it did not work. The same screen showed up. And i have been trying for the whole day, using Hamachi, reinstalling the game, and lowering my settings. One time i lowered my settings and it let me almost join, it said something along the lines of Fatally missing block and items. I searched up and it said to use the config of the server, i tried it and it went back to logging in. Please help, thanks.
• When trying  to open up game, this pops up: https://api.mclo.gs/1/raw/E6nMPZe
• Hello all, I am trying to figure out how to prevent a custom entity from walking over blocks. My Entity is extending PathfinderMob. I have tried setMapUpStep(0.6f), disabling jumping, and overriding getStepHeight and returning 0.6f. Any help would be greatly appreciated. Thank you! EDIT: Thought I should include MC and Forge versions. MC : 1.20.1 Forge: 47.3.0
• 🅱️org is better
• i tried starting the game, minecraft starts; crashes after a couple seconds of loading screen. heres the log: https://pastebin.com/a6aMcGYF im playing on curseforge launcher, forge 1.20.1 and got quite a few mods pls help

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...