- Home /
Destroy object if collision is strong enouf
Hi I am making a marble game and I was wondering how to make a script that could destroy an object if a marble is fast enouf. I hope you understand what I said... Thank you for answering.
Answer by fafase · Apr 06, 2012 at 09:04 AM
You could try a if statement inside the collision:
function OnCollisionEnter(other:Collision){
if(other.gameObject.tag =="box"){
if(velocity>=fastenuf){
Destroy(other.gameObject);
}
else {
bouncingFunction();
}
}
}
It says to me unknown velocity identifier, what should I do?
You are not supposed to use my code as is. This is more an algorithm than code. You need modify it with your own as I do not know what var names you are using. Velocity is used as general term here, you need to find the velocity magnitude. I guess you have a velocity(x,y,z) or named differently then use Vector3.magnitude(velocity)>=fastenuf.
To be more efficient don't use the velocity directly but the square velocity (less expensive) and compare with a square speed.
if( velocity.sqr$$anonymous$$agnitude >= (fastenough*fastenough) )
Your answer
Follow this Question
Related Questions
How do I increase speed after collision? 2 Answers
Make an object destroy the object it is touching? 2 Answers
Destroying Gate by hitting a switch 1 Answer
Problem with collisions and Destroy(gameObject). 2 Answers
If two of the same objects spawn on top of each other, is it possible to destroy only one? 0 Answers