How to make Spray on First Person Shooter Game

Hi I’m planning to make a Hotkey in my Game and when that hotkey is pressed I want my player to spray a Sprite Image in the wall.

I know it is possible because it is like making a bullet hole but my problem is that when the player Spray on the edge of the wall (“T”), the result will not like a spray on one of side wall??

Like on the picture I’ve added. I want a result like that :slight_smile: Thanks


You can achieve a similar result with a lot of ray casts. The method ill suggest is probably not ideal but it might work for you.

Consider a mesh like the following.

(You can consider using a mesh with less vertices).

And follow the steps below;

  1. Transform vertices of the mesh with world matrix of camera.

  2. Throw raycasts for every transformed vertice of the mesh at the direction of camera.

  3. Take all positoins that raycasts hits.

  4. Substract “raycast direction multiplied with some small constant” from all positions. (This step is important for your spray to look in front of the wall)

  5. Make a copy of original mesh.

  6. Set vertices of copy mesh to positions of all raycasts.

  7. Place the mesh to a mesh renderer whics stays at the center of the world axis.

  8. You should create a mesh pool and mesh renderer pool for better performance.

There might be better ways but this is all i can think right now.