Skip to content

Commit

Permalink
Remove get_closest_* methods from ShapeCast2D
Browse files Browse the repository at this point in the history
The physics API cannot provide needed functionality to ensure the correct behavior, which might lead to confusion (see `rest_info()`).

However `get_closest_collision_safe/unsafe_fraction()` methods are not removed, because they return correct result from `cast_motion()`.
  • Loading branch information
Andrii Doroshenko (Xrayez) committed Nov 12, 2021
1 parent f979d59 commit 6a67350
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 53 deletions.
25 changes: 0 additions & 25 deletions doc/classes/ShapeCast2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,6 @@
[b]Note:[/b] [code]enabled == true[/code] is not required for this to work.
</description>
</method>
<method name="get_closest_collider" qualifiers="const">
<return type="Object" />
<description>
Returns the first object that the shape intersects, or [code]null[/code] if no object is intersecting the shape (i.e. [method is_colliding] returns [code]false[/code]).
</description>
</method>
<method name="get_closest_collider_shape" qualifiers="const">
<return type="int" />
<description>
Returns the shape ID of the first object that the shape intersects, or [code]0[/code] if no object is intersecting the shape (i.e. [method is_colliding] returns [code]false[/code]).
</description>
</method>
<method name="get_closest_collision_normal" qualifiers="const">
<return type="Vector2" />
<description>
Returns the normal of the closest intersecting object's shape at the collision point.
</description>
</method>
<method name="get_closest_collision_point" qualifiers="const">
<return type="Vector2" />
<description>
Returns the collision point at which the shape intersects the closest object.
[b]Note:[/b] this point is in the [b]global[/b] coordinate system.
</description>
</method>
<method name="get_closest_collision_safe_fraction" qualifiers="const">
<return type="float" />
<description>
Expand Down
24 changes: 0 additions & 24 deletions scene/2d/shape_cast_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,6 @@ real_t ShapeCast2D::get_closest_collision_unsafe_fraction() const {
return collision_unsafe_fraction;
}

Object *ShapeCast2D::get_closest_collider() const {
ERR_FAIL_COND_V_MSG(result.is_empty(), nullptr, "Shape cast has not collided with anything yet.");
return ObjectDB::get_instance(result[0].collider_id);
}

int ShapeCast2D::get_closest_collider_shape() const {
ERR_FAIL_COND_V_MSG(result.is_empty(), -1, "Shape cast has not collided with anything yet.");
return result[0].shape;
}

Vector2 ShapeCast2D::get_closest_collision_point() const {
ERR_FAIL_COND_V_MSG(result.is_empty(), Vector2(), "Shape cast has not collided with anything yet.");
return result[0].point;
}

Vector2 ShapeCast2D::get_closest_collision_normal() const {
ERR_FAIL_COND_V_MSG(result.is_empty(), Vector2(), "Shape cast has not collided with anything yet.");
return result[0].normal;
}

void ShapeCast2D::set_enabled(bool p_enabled) {
enabled = p_enabled;
update();
Expand Down Expand Up @@ -437,10 +417,6 @@ void ShapeCast2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_collision_point", "index"), &ShapeCast2D::get_collision_point);
ClassDB::bind_method(D_METHOD("get_collision_normal", "index"), &ShapeCast2D::get_collision_normal);

ClassDB::bind_method(D_METHOD("get_closest_collider"), &ShapeCast2D::get_closest_collider);
ClassDB::bind_method(D_METHOD("get_closest_collider_shape"), &ShapeCast2D::get_closest_collider_shape);
ClassDB::bind_method(D_METHOD("get_closest_collision_point"), &ShapeCast2D::get_closest_collision_point);
ClassDB::bind_method(D_METHOD("get_closest_collision_normal"), &ShapeCast2D::get_closest_collision_normal);
ClassDB::bind_method(D_METHOD("get_closest_collision_safe_fraction"), &ShapeCast2D::get_closest_collision_safe_fraction);
ClassDB::bind_method(D_METHOD("get_closest_collision_unsafe_fraction"), &ShapeCast2D::get_closest_collision_unsafe_fraction);

Expand Down
4 changes: 0 additions & 4 deletions scene/2d/shape_cast_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ class ShapeCast2D : public Node2D {
Vector2 get_collision_point(int p_idx) const;
Vector2 get_collision_normal(int p_idx) const;

Object *get_closest_collider() const;
int get_closest_collider_shape() const;
Vector2 get_closest_collision_point() const;
Vector2 get_closest_collision_normal() const;
real_t get_closest_collision_safe_fraction() const;
real_t get_closest_collision_unsafe_fraction() const;

Expand Down

0 comments on commit 6a67350

Please sign in to comment.