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
The next code is what should destroy the bullet(clone) object once it hits something.
Sure is funny how things can go wrong with such simple things! Thank you in advance for the help!
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:
answered Jun 23 '10 at 02:53 AM
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!
answered Jun 23 '10 at 12:02 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. :)
answered Jun 24 '10 at 08:03 PM