Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FutchProductionsSyndicate · May 06, 2011 at 04:53 AM · raycastfollowshootbulletsdecal

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by BinaryCore · May 06, 2011 at 05:55 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Raycast Decals,Sound and MuzzleFlash not working too well 0 Answers

How i can repair my shoot decals? 2 Answers

How do I instantiate a projectile along the path of a raycast? 0 Answers

Raycasting to the middle of the screen? 2 Answers

GUI Follow RaycastHit 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges