RigidBody2D: add and bind get_inertia() method.
You can't set this value very well, since it's automatically computed from the mass and the collision shapes. But since the values are higher than many people might suspect, so being able to read it helps estimate the amount of torque you might need to apply.
This commit is contained in:
parent
dbabe4c07c
commit
f7d31cec38
6 changed files with 30 additions and 4 deletions
|
|
@ -186,6 +186,10 @@ float Body2DSW::get_param(Physics2DServer::BodyParameter p_param) const {
|
|||
case Physics2DServer::BODY_PARAM_MASS: {
|
||||
return mass;
|
||||
} break;
|
||||
case Physics2DServer::BODY_PARAM_INERTIA: {
|
||||
if(_inv_inertia == 0) return INFINITY;
|
||||
else return 1.0 / _inv_inertia;
|
||||
} break;
|
||||
case Physics2DServer::BODY_PARAM_GRAVITY_SCALE: {
|
||||
return gravity_scale;
|
||||
} break;
|
||||
|
|
|
|||
|
|
@ -677,6 +677,7 @@ void Physics2DServer::_bind_methods() {
|
|||
BIND_CONSTANT( BODY_PARAM_BOUNCE );
|
||||
BIND_CONSTANT( BODY_PARAM_FRICTION );
|
||||
BIND_CONSTANT( BODY_PARAM_MASS );
|
||||
BIND_CONSTANT( BODY_PARAM_INERTIA );
|
||||
BIND_CONSTANT( BODY_PARAM_GRAVITY_SCALE );
|
||||
BIND_CONSTANT( BODY_PARAM_LINEAR_DAMP);
|
||||
BIND_CONSTANT( BODY_PARAM_ANGULAR_DAMP);
|
||||
|
|
|
|||
|
|
@ -421,6 +421,7 @@ public:
|
|||
BODY_PARAM_BOUNCE,
|
||||
BODY_PARAM_FRICTION,
|
||||
BODY_PARAM_MASS, ///< unused for static, always infinite
|
||||
BODY_PARAM_INERTIA, // read-only: computed from mass & shapes
|
||||
BODY_PARAM_GRAVITY_SCALE,
|
||||
BODY_PARAM_LINEAR_DAMP,
|
||||
BODY_PARAM_ANGULAR_DAMP,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue