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 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
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
2
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
Add comment · 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 ins$$anonymous$$d.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Raycasr in my fps? 1 Answer

Help with getting a bullet to move. 2 Answers

Bullet does not move forward 1 Answer

Transform.position bullet won't align 1 Answer

How to get bullets to hit crosshair 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