summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-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;