- Home /
Question by
Krzychu94 · Nov 03, 2016 at 12:49 PM ·
forcerigidbody physicsoverloadrigidbody collision
Is there a way to add a variable in rigidbody? (like .position)
Hello!
I'm interested in adding my own variable (like .position or .mass) to a rigidbody or collision. For what i know, values like position or relativeVelocity updates every frame. I'd like to add .force value, to simply check actual force (as a multiplication of mass and derivative of velocity.magnitude).
Is there a way to do this?
Comment
Answer by tanoshimi · Nov 03, 2016 at 08:45 PM
You can't add a property, but you can add an extension method which is nearly the same...
public static Vector3 GetForce (this Rigidbody rigidbody) {
Vector3 result;
// Calculate result however you want using properties of rigidbody
return result;
}
Which you can then call on any rigidbody instance as:
Rigidbody myRigidbody;
myRigidbody.GetForce();
Your answer
