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
1
Question by JakeBryn · Nov 16, 2010 at 02:55 AM · collisionbulletraycasthit

Bullet Collision Simulation?

Hey I made a script where my FPS controller shoots a small bullet from an empty parented right in front of the camera... essentially sending a small bullet out as if in an FPS controller. The problem is that that collisions are quirky and fifty percent of the time the bullet passes right through the target without affecting it. I know how to make a script that adds force away from the camera with RayCastHit, but this is not realistic because no matter where i click the object it always apples force away from the player, where as a real bullet would push it where ever it hits the mesh and apply torque as well... etc. How can I simulate this "bullet collision" with a raycasthit or solve the collider problem?

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

2 Replies

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

Answer by Loius · Nov 16, 2010 at 03:23 AM

Does AddForceAtPosition help? It should be compatible with raycast-bullets and still give the torque component you're looking for.

If you need physical bullets, look up DontGoThroughThings (a community script on the wiki I believe), or use raycasts each frame to see if the bullet has skipped something it shouldn't have.

Comment
Add comment · Show 1 · 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 jkih0021 · Jun 25, 2012 at 12:56 PM 0
Share

Thanks for the script. I noticed the script checks only for objects in the specified layer. Does this imply I will get performance issues if I just spam the world with objects with the layer?

avatar image
0

Answer by Mike 12 · Nov 16, 2010 at 03:57 AM

You said "as if in an FPS controller"? What do you mean by that? The FPS controller, doesn't really use the PhysX engine to detect collisions. You could just try not to attach a character controller to your bullets if that's what you're trying to do.

Maybe you should try creating an empty game object with a collider and rigidbody attached to it and send it off from the gun that way.

I've had a similar experience with some bullet objects of my own, and they too would go through other game objects and the collisions were never detected. But, since I wasn't using the built-in Physics engine in Unity to do all the work and was performing my own calculations, I ended up using the RaycastHit class for my work.

Yet, like I said earlier, if you just simply create your own game object with a collider and rigidbody, then right after you've set the velocity for the object the object should fly through the environment and collide however you want it to.

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 bullet collision problem 1 Answer

How can I change this script? 0 Answers

Collision Detection between certain objects 2 Answers

Instantiated bullets hitting GameObjects? 4 Answers

Destroy Bullet On Collision? 1 Answer


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