summaryrefslogtreecommitdiffstats
path: root/scene/2d
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2023-11-08 16:56:19 -0600
committerAaron Franke <arnfranke@yahoo.com>2024-01-30 23:57:38 -0600
commitaed5ea946036e6c2c8a0165265bb6b038b3db8cb (patch)
tree97c2e825533617a2c3b12a45e6c5a09e06886b0b /scene/2d
parent313f623b9d102cc8c411ae7cab9518f98c2f87f2 (diff)
downloadredot-engine-aed5ea946036e6c2c8a0165265bb6b038b3db8cb.tar.gz
Expose a method to get gravity for any physics body
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/physics_body_2d.cpp5
-rw-r--r--scene/2d/physics_body_2d.h1
2 files changed, 6 insertions, 0 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 6af5a8dd80..7a131916e8 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -35,6 +35,7 @@
void PhysicsBody2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("move_and_collide", "motion", "test_only", "safe_margin", "recovery_as_collision"), &PhysicsBody2D::_move, DEFVAL(false), DEFVAL(0.08), DEFVAL(false));
ClassDB::bind_method(D_METHOD("test_move", "from", "motion", "collision", "safe_margin", "recovery_as_collision"), &PhysicsBody2D::test_move, DEFVAL(Variant()), DEFVAL(0.08), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_gravity"), &PhysicsBody2D::get_gravity);
ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody2D::get_collision_exceptions);
ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody2D::add_collision_exception_with);
@@ -145,6 +146,10 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_motion
return PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), parameters, r);
}
+Vector2 PhysicsBody2D::get_gravity() const {
+ return PhysicsServer2D::get_singleton()->body_get_direct_state(get_rid())->get_total_gravity();
+}
+
TypedArray<PhysicsBody2D> PhysicsBody2D::get_collision_exceptions() {
List<RID> exceptions;
PhysicsServer2D::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions);
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 208e72c40f..62636b02f4 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -52,6 +52,7 @@ protected:
public:
bool move_and_collide(const PhysicsServer2D::MotionParameters &p_parameters, PhysicsServer2D::MotionResult &r_result, bool p_test_only = false, bool p_cancel_sliding = true);
bool test_move(const Transform2D &p_from, const Vector2 &p_motion, const Ref<KinematicCollision2D> &r_collision = Ref<KinematicCollision2D>(), real_t p_margin = 0.08, bool p_recovery_as_collision = false);
+ Vector2 get_gravity() const;
TypedArray<PhysicsBody2D> get_collision_exceptions();
void add_collision_exception_with(Node *p_node); //must be physicsbody