Bullet holes where you shoot

Hey! I am currently making a game and wanted to know how to properly position bullet holes on the surface you shoot. It raycasts from the camera to an entity positioned further away from the camera in a straight line.

Game Link: PlayCanvas 3D HTML5 Game Engine

Hey @Cryptonaph,

That should be possible, if slightly complex. To create decals in PlayCanvas I’d recommend you to create a quad (A plane mesh), then lay over the desired texture on the quad. There is a full example of precisely what you want being done, though with stars instead of bullet holes.

If you’re interested in doing this, I’d probably recommend you first start by reading up on Mesh Generation and how it works in PlayCanvas. Then I’d go back to the example on Mesh Decals and try to rebuild it.

Let me know if you need further guidance!

EDIT: It has also been brought to my attention that this public decal script exists.


So I read the API Reference for the Mesh Generation, but how would I incorporate that? I’m not sure how I can use that with what I currently have made. Is there any way I can just make it so it makes the mesh when given an entity? If it’s hard to understand what I’m trying to say, that’s because I am insanely tired and woke up 3 hours ago, so I’ll just give a screenshot instead.

Basically, how could I add a script to Map which generates the proper mesh that includes every child object? Is that possible? I feel that could also be good for a NavMesh as well.

Also, I checked out the decal script you linked, and as cool as it is, I see one problem with it and its how it stretches the decal when you hit at an angle.

This is what I mean by that, lets say I hit the corner, that decal stretches way past the corner, and if I did so with a bullet hole it would not look correct.

But give me a moment while I try the first linked example…

Edit: nevermind I can’t comprehend this code, is there a playcanvas project with it? I don’t know how I would use it with raycast results. :sweat_smile:

Hi @Cryptonaph I think that the method suggested by @poliveira is exactly what you are looking for with modifications and some explanation. If you look at a lot of other game engine examples on YouTube for creating Hit Sprites or Bullet Holes the method is almost always the same with the exception of the programming language. Here is my view of the basics:

  1. Get the start point of the Raycast from the player.
  2. Clone the hit Sprite or Bullet Hole texture.
  3. Enable the Bullet Hole object cloned.
  4. Get the resulting point or collision point of the Raycast.
  5. The resulting entity that has been collided with.
  6. Move the hit Sprite/Bullet Hole to the entity and align to it’s NORMAL surface of entity. (i.e. turn it so it lay over top of the entity.

Here is a support question which was answered some time ago. Actually I think before I joined.

Maybe @poliveira could get some more incite to help resurrect this from the past.

Hey @Cryptonaph,

While the discussion Tirk182 brought up is actually a great starting point, I’ve stumbled into this example project earlier today, which may be simpler for you to understand. You can open it and examine the scripts to understand what is going on.


Yes! Thank you, this is much easier to understand. However, I would like to ask for help, such as a step by step guide on how I would integrate this into my game. If that can’t be done then that is perfectly fine and I will take a hiatus to learn how this works fully.