[solved] Possible to extend rigidbody?

I need to calculate some more “advanced” physics for sphere shapes (laminant turbular drag and magnus force).

I would like to be able to just extend the built in physics and add these calculations, is that possible? Or what would be the best way of doing that?

Thanks

You cannot extend a built-in Unity class directly. So, you cannot go into the Rigidbody class and add methods or variables or properties or all that stuff :smile:.

I assume that you have determined you cannot get the effect you want by tweaking the rigidbody, joint, or physic material so then:

What you should probably do is create a script that calculates these and then apply them to the Rigidbody. So for drag, you might do somthing like:

public Rigidbody rB;

void Start () {
     Rigidbody rB = rigidbody;
}

void Update () {
     Vector3 velocity = rB.velocity;
     Vector3 negativeForce = CalculateDragFromSpeed(velocity);
     rB.AddForce(negativeForce);
}

Vector3 CalculateDragFromSpeed(Vector3 curVelocity) {
     return curVelocity + magic;
}
1 Like

Ah, so that is how you do it. Thank you so much for answering Peter, that is exactly what I wanted.