summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorRicardo Buring <ricardo.buring@gmail.com>2022-04-28 22:44:09 +0200
committerRicardo Buring <ricardo.buring@gmail.com>2022-05-18 16:40:29 +0200
commitf072aa69a99a436b711afeb4b2b1c10b93883606 (patch)
tree1fab336eed96d0da16923fcbe54c5a5b3500cb45 /servers
parentcdc5da746032c2caad8539480514f444bb1eb1ad (diff)
Add motion parameter to toggle whether recovery is reported as a collision
This makes the intent explicit in each use case.
Diffstat (limited to 'servers')
-rw-r--r--servers/physics_2d/godot_space_2d.cpp2
-rw-r--r--servers/physics_3d/godot_space_3d.cpp2
-rw-r--r--servers/physics_server_2d.cpp4
-rw-r--r--servers/physics_server_2d.h4
-rw-r--r--servers/physics_server_3d.cpp4
-rw-r--r--servers/physics_server_3d.h4
6 files changed, 18 insertions, 2 deletions
diff --git a/servers/physics_2d/godot_space_2d.cpp b/servers/physics_2d/godot_space_2d.cpp
index 731eab2dfe..0a7859d86a 100644
--- a/servers/physics_2d/godot_space_2d.cpp
+++ b/servers/physics_2d/godot_space_2d.cpp
@@ -874,7 +874,7 @@ bool GodotSpace2D::test_body_motion(GodotBody2D *p_body, const PhysicsServer2D::
bool collided = false;
- if (recovered || (safe < 1)) {
+ if ((p_parameters.recovery_as_collision && recovered) || (safe < 1)) {
if (safe >= 1) {
best_shape = -1; //no best shape with cast, reset to -1
}
diff --git a/servers/physics_3d/godot_space_3d.cpp b/servers/physics_3d/godot_space_3d.cpp
index 9c051b23f6..2bdaf581a1 100644
--- a/servers/physics_3d/godot_space_3d.cpp
+++ b/servers/physics_3d/godot_space_3d.cpp
@@ -906,7 +906,7 @@ bool GodotSpace3D::test_body_motion(GodotBody3D *p_body, const PhysicsServer3D::
}
bool collided = false;
- if (recovered || (safe < 1)) {
+ if ((p_parameters.recovery_as_collision && recovered) || (safe < 1)) {
if (safe >= 1) {
best_shape = -1; //no best shape with cast, reset to -1
}
diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp
index 4aeaa7497f..3259bd6ef9 100644
--- a/servers/physics_server_2d.cpp
+++ b/servers/physics_server_2d.cpp
@@ -505,12 +505,16 @@ void PhysicsTestMotionParameters2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_exclude_objects"), &PhysicsTestMotionParameters2D::get_exclude_objects);
ClassDB::bind_method(D_METHOD("set_exclude_objects", "exclude_list"), &PhysicsTestMotionParameters2D::set_exclude_objects);
+ ClassDB::bind_method(D_METHOD("is_recovery_as_collision_enabled"), &PhysicsTestMotionParameters2D::is_recovery_as_collision_enabled);
+ ClassDB::bind_method(D_METHOD("set_recovery_as_collision_enabled", "enabled"), &PhysicsTestMotionParameters2D::set_recovery_as_collision_enabled);
+
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", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude_bodies", "get_exclude_bodies");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_objects"), "set_exclude_objects", "get_exclude_objects");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "recovery_as_collision"), "set_recovery_as_collision_enabled", "is_recovery_as_collision_enabled");
}
///////////////////////////////
diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h
index bd53764932..745ee38ee1 100644
--- a/servers/physics_server_2d.h
+++ b/servers/physics_server_2d.h
@@ -485,6 +485,7 @@ public:
bool collide_separation_ray = false;
RBSet<RID> exclude_bodies;
RBSet<ObjectID> exclude_objects;
+ bool recovery_as_collision = false;
MotionParameters() {}
@@ -727,6 +728,9 @@ public:
Array get_exclude_objects() const;
void set_exclude_objects(const Array &p_exclude);
+
+ bool is_recovery_as_collision_enabled() const { return parameters.recovery_as_collision; }
+ void set_recovery_as_collision_enabled(bool p_enabled) { parameters.recovery_as_collision = p_enabled; }
};
class PhysicsTestMotionResult2D : public RefCounted {
diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp
index d05f5128b2..63085cf275 100644
--- a/servers/physics_server_3d.cpp
+++ b/servers/physics_server_3d.cpp
@@ -527,6 +527,9 @@ void PhysicsTestMotionParameters3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_exclude_objects"), &PhysicsTestMotionParameters3D::get_exclude_objects);
ClassDB::bind_method(D_METHOD("set_exclude_objects", "exclude_list"), &PhysicsTestMotionParameters3D::set_exclude_objects);
+ ClassDB::bind_method(D_METHOD("is_recovery_as_collision_enabled"), &PhysicsTestMotionParameters3D::is_recovery_as_collision_enabled);
+ ClassDB::bind_method(D_METHOD("set_recovery_as_collision_enabled", "enabled"), &PhysicsTestMotionParameters3D::set_recovery_as_collision_enabled);
+
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "from"), "set_from", "get_from");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "motion"), "set_motion", "get_motion");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin"), "set_margin", "get_margin");
@@ -534,6 +537,7 @@ void PhysicsTestMotionParameters3D::_bind_methods() {
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", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_exclude_bodies", "get_exclude_bodies");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude_objects"), "set_exclude_objects", "get_exclude_objects");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "recovery_as_collision"), "set_recovery_as_collision_enabled", "is_recovery_as_collision_enabled");
}
///////////////////////////////
diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h
index c707f621b4..6a721f75a3 100644
--- a/servers/physics_server_3d.h
+++ b/servers/physics_server_3d.h
@@ -522,6 +522,7 @@ public:
bool collide_separation_ray = false;
RBSet<RID> exclude_bodies;
RBSet<ObjectID> exclude_objects;
+ bool recovery_as_collision = false;
MotionParameters() {}
@@ -941,6 +942,9 @@ public:
Array get_exclude_objects() const;
void set_exclude_objects(const Array &p_exclude);
+
+ bool is_recovery_as_collision_enabled() const { return parameters.recovery_as_collision; }
+ void set_recovery_as_collision_enabled(bool p_enabled) { parameters.recovery_as_collision = p_enabled; }
};
class PhysicsTestMotionResult3D : public RefCounted {