- Home /
The question is answered, right answer was accepted
G-Mod like physics that kill?
So I'm currently trying to make it so that when parts of my collapsible buildings fall down, it kills the player. How can I do that? EXAMPLE script strongly suggested.
EDIT : NO ONCOLLIDERENTER!!! ONLY MASSIVE WEIGHT AND STRONG FALLING RIGID BODIES.
EDIT 2 : IM SORRY I MEANT I DIDNT WANT TO DAMAGE PLAYER WHEN ONCOLLIDERENTER. Sorry. :P
EDIT 3 : When I said EXAMPLE script I meant something to start me, not a full script. People hate people for that now??? T.T
A collision event is what you need, so I don't know why you're discounting it. You can check the mass and velocity of the rigidbody to decide what happens.
you want to destroy a game object (or do damage, maybe?) when debris is hitting the player, but you don't want to do any detection of when this would occur?
I'm sorry I meant like kill on collider enter is not what I want. Sorry!
Answer by Cornotiberious · Jul 16, 2013 at 01:57 AM
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.OnCollisionEnter.html
you can do a little tweaking on the second code, and get exactly what you're looking for. instead of having the code instantiate a prefab, have the code ask
if(rigidbody.mass>50){
player.GetComponent(Health).hurt(damage);
}
and that should only cause damage if the mass is over 50(you can change it to whatever number you want. (you could also make it do damage based on how massive the object is)
if(rigidbody.mass>50){
player.GetComponent(Health).hurt(rigidbody.mass);
}
Does that help?
All good but how about velocity? I mean just because a rigid body over the mass of 50 touching you wouldn't damage you right? Other than that, thanks. A lot of dislikes.
You likely got the dislikes for "EXA$$anonymous$$PLE script strongly suggested." Too many posters look to people on the site to write their scripts for them rather than learning how to solve their own problems. So any references to asking for scripts gets thumbs down, and often the questions are closed.
As for 'velocity', change your check to:
if(rigidbody.mass * rigidbody.velocity.magnitude > some_value){
You might also want to tweak this check to better reflect the actual equation for kinetic energy and see if it fits your needs better.
http://en.wikipedia.org/wiki/$$anonymous$$inetic_energy#Newtonian_kinetic_energy
if((rigidbody.mass * (rigidbody.velocity.magnitude * rigidbody.velocity.magnitude)) / 2.0f > some_value)
When I said example script I meant something like this, not like a full script so I can get a head start. T.T Anyways, thanks bro.