- Home /
How do you cause damage based on object Velocity?
In my game you can pick up object. You can throw objects. You can also launch little rigidbody balls. The problem is, I can't figure out how to make the thrown objects cause damage upon image using velocity to determine how much damage it causes.
For example: If you throw an object and hit something at point blank range, it's going to hurt 25. If you hit something from about 15 feet away, it will cause 5 damage. I can control the air friction myself.
Has anyone done this before or can help with this?
Thank you!
Your projectiles are rigidbodies? It really sounds like you could just pull the magnitude of their velocity and use that to scale damage:
float maxVelocityConsidered = 50f;
float v = rigidbody.velocity.magnitude;
float factor = v / maxVelocityConsidered;
factor = $$anonymous$$athf.Clamp01( factor );
float damage = $$anonymous$$athf.Lerp(25, 5, factor);
Your answer
Follow this Question
Related Questions
Damaging Enemy strangely not working. 0 Answers
AddForce moving object in wrong direction 1 Answer
Damage with collision force? 0 Answers
Problem with damaging game object 1 Answer
Dragging object out of position 2 Answers