• 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
Question by CommitteeWind · Mar 17, 2011 at 07:47 PM · fpsshootingbulletgun

Bullet Collision Issues

Right now my bullets are just spheres with rigid bodies (continuous-dynamic) attached to them. In order to shoot them I do:

1.Create the projectile using Instantiate 2. In Projectile.Start() do:

this.GetComponent<Rigidbody>().AddForce(transform.forward * this.TrajectoryInformation.MuzzleVelocity * 500000 * Time.deltaTime);

This moves the bullet quickly (which I want), but it sends other objects flying which I do not want. Also, I attempt to apply a decal at the location of the hit like so:

Vector3 hitPosition = new Vector3 { x = collision.contacts[0].point.x, y = collision.contacts[0].point.y, z = collision.contacts[0].point.z };

     Quaternion rotation = Quaternion.Euler(collision.contacts[0].normal);

     //Create the decal (ie: bullet hole)
     GameObject decal = (GameObject)Instantiate(DecalPrefab, hitPosition, rotation);

     //Makes sure the decal stays on whatever it hit
     decal.transform.parent = collision.collider.transform;

This sometimes creates a decal but the decal is never rotated properly.

Any ideas on how to fix these things?

Comment

People who like this

0 Show 0
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
Best Answer

Answer by Niklas · Mar 17, 2011 at 08:46 PM

You say your decal sometimes works? Maby the bullet is so fast that the collision detection dont work. Have you tried to extrapolate the rigidbody?

If the bullet is intended to fly fast, maby it is better to do the collision detection with a ray, place the decal at the collided position and just use the model of the bullet for visuals.

Comment
DaveA
CommitteeWind

People who like this

2 Show 3 · 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
avatar image DaveA · Mar 17, 2011 at 11:04 PM 0
Share

Exactly. Unless you NEED to see the bullet fly (like it's pretty slow, which yours is not), use Raycast instead.

avatar image CommitteeWind · Mar 17, 2011 at 11:27 PM 0
Share

Thanks, I hadn't considered that rays would be a good idea for fast moving bullets. I don't suppose its feasible to also create a tracer/trail renderer? and what would the physics be like if I did this? Would I create a ray from the bullet start position (tip of gun) to the point where the camera is looking and then create some sort of explosion at the point of contact?

avatar image Niklas · Mar 18, 2011 at 08:18 AM 0
Share

Well it depends entirely on what you want to do with this. You could just as well draw the line from the head as well since this will not be visible and it might feel better. You need to try and see which is best for your situation

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Help with fire script 1 Answer

How do i adjust the projectile path and direction? 1 Answer

How do I fire multiple bullets in an arc? 2 Answers

FPS Shoooting Problem 1 Answer

Which is better, shooting a bullet from camera or from the gun itself? 3 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