summaryrefslogtreecommitdiffstats
path: root/servers/physics_server_2d.cpp
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2021-09-30 11:05:30 -0700
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2021-10-04 12:27:42 -0700
commit4f8d761be632a9d342655aa88a0745465b2177b8 (patch)
tree4ad9b5bffd91a1ce2a30a8a60621e6ccfbadd8fa /servers/physics_server_2d.cpp
parent5b270278c869461a3dce2c0d0db71e0beaa50685 (diff)
downloadredot-engine-4f8d761be632a9d342655aa88a0745465b2177b8.tar.gz
Fix physics glitch with TileMap moving platforms
Added a parameter in test_body_motion to exclude attached objects from collision, used to avoid collision with all TileMap tiles with moving platform motion instead of just the one tile the character touches. Same changes made in 3D for consistency, and handling potential similar cases.
Diffstat (limited to 'servers/physics_server_2d.cpp')
-rw-r--r--servers/physics_server_2d.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp
index ad53f9ed20..fe2970912a 100644
--- a/servers/physics_server_2d.cpp
+++ b/servers/physics_server_2d.cpp
@@ -430,6 +430,26 @@ void PhysicsTestMotionParameters2D::set_exclude_bodies(const Vector<RID> &p_excl
}
}
+Array PhysicsTestMotionParameters2D::get_exclude_objects() const {
+ Array exclude;
+ exclude.resize(parameters.exclude_objects.size());
+
+ int object_index = 0;
+ for (ObjectID object_id : parameters.exclude_objects) {
+ exclude[object_index++] = object_id;
+ }
+
+ return exclude;
+}
+
+void PhysicsTestMotionParameters2D::set_exclude_objects(const Array &p_exclude) {
+ for (int i = 0; i < p_exclude.size(); ++i) {
+ ObjectID object_id = p_exclude[i];
+ ERR_CONTINUE(object_id.is_null());
+ parameters.exclude_objects.insert(object_id);
+ }
+}
+
void PhysicsTestMotionParameters2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_from"), &PhysicsTestMotionParameters2D::get_from);
ClassDB::bind_method(D_METHOD("set_from"), &PhysicsTestMotionParameters2D::set_from);
@@ -446,11 +466,15 @@ void PhysicsTestMotionParameters2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_exclude_bodies"), &PhysicsTestMotionParameters2D::get_exclude_bodies);
ClassDB::bind_method(D_METHOD("set_exclude_bodies"), &PhysicsTestMotionParameters2D::set_exclude_bodies);
+ ClassDB::bind_method(D_METHOD("get_exclude_objects"), &PhysicsTestMotionParameters2D::get_exclude_objects);
+ ClassDB::bind_method(D_METHOD("set_exclude_objects"), &PhysicsTestMotionParameters2D::set_exclude_objects);
+
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "from"), "set_from", "get_from");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion"), "set_motion", "get_motion");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin"), "set_margin", "get_margin");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_separation_ray"), "set_collide_separation_ray_enabled", "is_collide_separation_ray_enabled");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_bodies"), "set_exclude_bodies", "get_exclude_bodies");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_objects"), "set_exclude_objects", "get_exclude_objects");
}
///////////////////////////////