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 Panamamigo · Jun 23, 2010 at 02:43 AM · collisiondestroybulletshoot

Why won't my bullets detect a collision and be destroyed?...

Hello everyone, I am very new to these forums but have been messing with Unity for a while now. I am trying to make a simple game just playing around (basic primitives, etc.). However I have already hit a wall.... In the game I'm making a blue cube shoots a little blue ball at a red cube. I would like the little blue ball to disappear when it collides with anything; the red cube, something else, myself, etc. This little blue bullet shoots slowly so I don't want to use RayCasts because I want to see the bullet at all times. I have it now as a rigidbody, unaffected by gravity so that it doesn't drop as it flies through the air. No matter what I do and no matter how hard I search I cannot find a way to make it detect the collision and destroy itself! All of the collision scripts add in explosion prefabs and sounds and things, but all I want is for the cube to simply vanish when it hits another object. Be it the character with a charactercontroller or a rigidbody. I will now insert two of the scripts I am using for the bullet prefab, if someone can alert me to a means of posting the whole scene on the internet or on this site for better clarity I would gladly post it.

This first code is to make the bullets disappear if they don't hit something

var lifespan= 5;

function Update () {

 Destroy(gameObject,lifespan);

}

The next code is what should destroy the bullet(clone) object once it hits something.

function OnCollisionEnter(collision : Collision){

 Destroy(gameObject);

}

Sure is funny how things can go wrong with such simple things! Thank you in advance for the help!

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

4 Replies

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

Answer by JonManatee · Jun 23, 2010 at 02:53 AM

I don't see any problems with your code, other than that you may not want to have Destroy(gameObject, lifespan) in Start instead of Update

Some simple troubleshooting to help you along:

  1. If there are compile errors in any of your scripts, Unity may revert to an older version until the bugs are fixed (the version where they don't disappear).
  2. Make sure your scripts are attached to a parent of the renderer
  3. Make sure that you have a collider attached to the GameObject with the scripts on it.
  4. Make sure the objects you want it to collide with have colliders
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 HardStyle · Apr 04, 2012 at 05:54 PM

another problem may be if your bullet is traveling 2 fast, if for 1 update the speed of bullet is bigger then a wall it will pass ....you need to use raycasts to fix this, not colisions

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 BoredKoi · Jun 23, 2010 at 12:02 PM

I cannot find a way to make it detect the collision and destroy itself!

I recently helped another person on the forums with similar questions in understanding the usage between Collisions and Triggers, perhaps that will help (about 10 posts down on the first page of the thread): Unity Scripting Forum post

The matrix at the bottom of the collider pages is what you need to review; if you don't understand how Static and isTrigger (Colliders) and isKinematic (rigidbodies) change those behaviors then you'll spend a lot of time with frustrating trial and error.

Hope you find this useful!

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 Panamamigo · Jun 24, 2010 at 08:03 PM

I'm not exactly sure what I was doing wrong either, but I just started a completely new project and re-attempted everything and it works perfect!

Thank you all for your responses they have been very helpful. :)

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

1 Person is following this question.

avatar image

Related Questions

Have bullets be destroyed when they collide with ANY collider 0 Answers

shoot game - 2 problems 1 Answer

Destroy Turret with machine Gun 0 Answers

destroy ''fireball'' on collision 2 Answers

How do you make a bullet disappear upon contact with another object 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