From 160346f7946dd70eb5787214c02d3c181f7ca782 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Thu, 4 Nov 2021 11:43:30 -0700 Subject: [PATCH] Add support for motion in 2D intersect_shape function It was only missing extended rect for broadphase check, the solver was already taking the motion from parameters into account. --- doc/classes/Physics2DDirectSpaceState.xml | 3 +-- servers/physics_2d/space_2d_sw.cpp | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/classes/Physics2DDirectSpaceState.xml b/doc/classes/Physics2DDirectSpaceState.xml index 6cc61535f5b..4706560f18c 100644 --- a/doc/classes/Physics2DDirectSpaceState.xml +++ b/doc/classes/Physics2DDirectSpaceState.xml @@ -100,8 +100,7 @@ - Checks the intersections of a shape, given through a [Physics2DShapeQueryParameters] object, against the space. - [b]Note:[/b] This method does not take into account the [code]motion[/code] property of the object. The intersected shapes are returned in an array containing dictionaries with the following fields: + Checks the intersections of a shape, given through a [Physics2DShapeQueryParameters] object, against the space. The intersected shapes are returned in an array containing dictionaries with the following fields: [code]collider[/code]: The colliding object. [code]collider_id[/code]: The colliding object's ID. [code]metadata[/code]: The intersecting shape's metadata. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data]. diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 9913547a23e..63ed002a679 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -210,6 +210,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID &p_shape, const Trans ERR_FAIL_COND_V(!shape, 0); Rect2 aabb = p_xform.xform(shape->get_aabb()); + aabb = aabb.merge(Rect2(aabb.position + p_motion, aabb.size)); //motion aabb = aabb.grow(p_margin); int amount = space->broadphase->cull_aabb(aabb, space->intersection_query_results, Space2DSW::INTERSECTION_QUERY_MAX, space->intersection_query_subindex_results);