- Home /
Collision with a coin
As I am new to unity, I need some help with collision with a coin. The problem is the my character object is a rigid body so when I collide with my coin object my object is affected by its physics. EX. A ball hit on a ledge and rolls in another direction. i need my coin to not affect my object in this way and almost be as invincible but still be destroyed when i collide with it. My collision code is this, function OnCollisionEnter(collision : Collision) {
if (collision.gameObject.name == "Coin"){
Destroy(collision.gameObject);
}}
Now this works perfectly fine, its just that i need the physic collision to be ignored. Is there a work around this? Any help will be good for me.
You could set the masses appropriate for the objects so that the coin has only an tiny impact on the player - or you could not use a physics simulation on the player/or the coin and just use a kinematic rigidbody you control yourself.
Simply make the coin's collider a trigger so it won't interact with other colliders. This is easily done by checking the IsTrigger option in the object's properties in the inspector window. Then trap the trigger collision in the OnTriggerEnter() method.
http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerEnter.html
Which is fine so long as the coin needs to have no physical interaction with anything else I guess.
THAN$$anonymous$$ You, Its works perfectly fine with is trigger on now. Sorry for such a simple question BTW.
it's not a simple question, it raises a critical point a lot of newcomers don't know about. in most cases, it's essential that everything in your game has real world sizes in meters and real world masses in kilogrrams. it's also essential that the "physic material" you use is correct for the object like in the real world. you should got through and do that now!
one of the most famous video game designers in japan, his hobby is guessing the size in cm of objects (I mean in the reel world!) He goes around with a little ruler for this purpose. I make an effort to try to know the mass of things in the real world. In $$anonymous$$G you should know how much the chair you are sitting in weighs, an iPad, a desk, a car, a bus, a small dog, a large dog, a leg, a football, and so on.
So it's a great question!