summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJosh Grams <josh@qualdan.com>2016-04-20 20:49:37 -0400
committerJosh Grams <josh@qualdan.com>2016-04-20 20:49:37 -0400
commitf7d31cec38c795909c4d1e0917f54aa118d380d7 (patch)
tree842bb5cd786dbce408bb7f5c563a9502542c05eb /scene
parentdbabe4c07cd9c0d825c14b961bd472f77e525162 (diff)
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.
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/physics_body_2d.cpp7
-rw-r--r--scene/2d/physics_body_2d.h2
2 files changed, 9 insertions, 0 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index cc6145677e..933e1579b2 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -602,6 +602,11 @@ real_t RigidBody2D::get_mass() const{
return mass;
}
+real_t RigidBody2D::get_inertia() const{
+
+ return Physics2DServer::get_singleton()->body_get_param(get_rid(),Physics2DServer::BODY_PARAM_INERTIA);
+}
+
void RigidBody2D::set_weight(real_t p_weight){
set_mass(p_weight/9.8);
@@ -868,6 +873,8 @@ void RigidBody2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_mass","mass"),&RigidBody2D::set_mass);
ObjectTypeDB::bind_method(_MD("get_mass"),&RigidBody2D::get_mass);
+ ObjectTypeDB::bind_method(_MD("get_inertia"),&RigidBody2D::get_inertia);
+
ObjectTypeDB::bind_method(_MD("set_weight","weight"),&RigidBody2D::set_weight);
ObjectTypeDB::bind_method(_MD("get_weight"),&RigidBody2D::get_weight);
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 40cb25d8c1..7523413df3 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -217,6 +217,8 @@ public:
void set_mass(real_t p_mass);
real_t get_mass() const;
+ real_t get_inertia() const; // read-only: auto-computed from mass & shapes.
+
void set_weight(real_t p_weight);
real_t get_weight() const;