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 GuyFawkes · Oct 14, 2011 at 03:05 AM · rigidbodycollision detectionstatic

How to detect collision with a rigidbody?

I'm trying to figure out how to detect the collision of a rigidbody (a bullet) with another object, such as a player, a target (not necessarily a rigidbody, unless it needs to be). How would I do this?

Update: I tried using this code:

 function OnCollisionEnter(collision : Collision) 
 {
     Destroy (gameObject);
 }

It was meant to destroy the bullet (where the script is contained), but it didn't work. I'm not sure if this matters but, the bullet is a rigid body with collision detection set to continous. What it's colliding with isn't a rigidbody, and it has a mesh collider on it. But the thing is that what I'm trying to make the bullet detect the collision on is imported, and has a mesh collider on it, not a box collider. So what would I do about that?

Comment
Add comment · Show 1
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 chemicalvamp · Oct 14, 2011 at 08:25 PM 0
Share

Bullets tend to move too fast for collision detection to be infallible changing your rigid body's collision type to continuous dynamic if it moves or continuous if it doesnt can help but the increase of collision check frequency increases load on your processor thats why its usually a better idea to use a raycast to detect whether or not the bullet hit. furthermore its also possible implement penetrating shots if you use raycastall.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Aleron · Oct 14, 2011 at 03:39 AM

There's a basic example in the documentation: http://unity3d.com/support/documentation/ScriptReference/Rigidbody.OnCollisionEnter.html

Basically, you implement your behavior in the OnCollisionEnter() method for your bullet rigid body.

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
avatar image
0

Answer by Eric5h5 · Oct 14, 2011 at 03:30 AM

http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

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
avatar image
0

Answer by Dhruvil · Oct 14, 2011 at 06:56 AM

Use OnTrigger instead of onCollision... It would be much better to used in arcade game collision...

http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnTriggerEnter.html

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why my capsule collider sometimes stucks in other colliders? 0 Answers

Having a kinematic rigidbody detect collision with a collider without a rigidbody 7 Answers

Static, Non movable rigidbody 4 Answers

Can i Move/Rotate triggers without Rigidbodies? And other collider questions. 3 Answers

Problem with CharacterController collision detection 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