x


2D Bullet texture follow ray and Bullet Holes

I have a gun shooting RayCasts. I would like to have 2d bullet textures shooting off from the gun, following the rays, to simulate the bullets being fired. How would i go about doing this?

I have the ray instintate a bullet hole prefab when it collides with a collider, how can i make this not fill up my hierarchy with clones? I have heard about using decals for this prpose, but cannot figure out how to do that.

Thanks!

more ▼

asked May 06 '11 at 04:53 AM

FutchProductionsSyndicate gravatar image

FutchProductionsSyndicate
225 18 21 25

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

There are many ways to make bullets follow a ray based on the desired behavior:

  • You can use a particle emitter for your gun that fires billboarded particles using the stretched setting in the particle renderer component and then add a world particle collider component to your particle emitter object and set it to send collision messages. This way you can fire off very fast particles (even 1000 mps or better) and the collisions won't miss.

Then when the particles collide with stuff, you can get the particle's collider transform from the OnCollisionEnter handler and spawn your decal for the bullet hole to paste it on the object.

  • You can of course also make mesh particles and/or also roll your own bullet code, even doing something like a raycast for hit detection and just animate particles moving through space for a visual effect even though you don't put collision on those meshes.

  • Or you can make meshes do the collision for bullets and turn up the physics timestep in your Edit->Time-> menu settings for the project. (I don't recommend this way because it's expensive on the CPU and you aren't guaranteed to always get a collision. I've still gotten collision misses even with physics checks set to Continuous Dynamic.)

Now, to not fill up your hierarchy view with bullet decal instances, simply create a parent game object in your scene and call it "Bullet Holes". Then every time you instantiate a new bullet hole, make the "Bullet Holes" object the parent to that bullet hole object so in your scene you will only see the parent object unless you expand the view to see the bullet hole decals.

I recommend you just preallocate one fixed bullet hole queue once on game startup and then cycle/reuse the bullet hole queue as new bullets hit things. Make the queue like 100 holes or something and then just keep cycling them. That way you aren't getting GC hitching from continuously creating new ones at runtime.

~hope that helps. gl

more ▼

answered May 06 '11 at 05:55 AM

BinaryCore gravatar image

BinaryCore
131 1 2 8

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1537
x329
x316
x69
x60

asked: May 06 '11 at 04:53 AM

Seen: 1894 times

Last Updated: May 06 '11 at 04:53 AM