summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2016-10-22 12:40:14 +0200
committerGitHub <noreply@github.com>2016-10-22 12:40:14 +0200
commitafd86ee240301aef499e35767cb3e12a7d36d948 (patch)
tree3a0c49bc4b168ee94646d9644ba7ea2cb7cfd83c /scene/2d
parentc23e8797f1bec30defd1903cfeef0992cb1f1a89 (diff)
parent8d57640d3745084d5c4abc4e6926298c2f4a3fb4 (diff)
Merge pull request #6090 from WalasPrime/raytrace_force
Added force_raycast_update GDScript method for RayCast[2D]
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/ray_cast_2d.cpp48
-rw-r--r--scene/2d/ray_cast_2d.h3
2 files changed, 30 insertions, 21 deletions
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index b5d62adfb4..bd7f4faae5 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -187,39 +187,44 @@ void RayCast2D::_notification(int p_what) {
if (!enabled)
break;
+ _update_raycast_state();
- Ref<World2D> w2d = get_world_2d();
- ERR_BREAK( w2d.is_null() );
-
- Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(w2d->get_space());
- ERR_BREAK( !dss );
-
- Matrix32 gt = get_global_transform();
+ } break;
+ }
+}
- Vector2 to = cast_to;
- if (to==Vector2())
- to=Vector2(0,0.01);
+void RayCast2D::_update_raycast_state() {
+ Ref<World2D> w2d = get_world_2d();
+ ERR_FAIL_COND( w2d.is_null() );
- Physics2DDirectSpaceState::RayResult rr;
+ Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(w2d->get_space());
+ ERR_FAIL_COND( !dss );
- if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask,type_mask)) {
+ Matrix32 gt = get_global_transform();
- collided=true;
- against=rr.collider_id;
- collision_point=rr.position;
- collision_normal=rr.normal;
- against_shape=rr.shape;
- } else {
- collided=false;
- }
+ Vector2 to = cast_to;
+ if (to==Vector2())
+ to=Vector2(0,0.01);
+ Physics2DDirectSpaceState::RayResult rr;
+ if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask,type_mask)) {
- } break;
+ collided=true;
+ against=rr.collider_id;
+ collision_point=rr.position;
+ collision_normal=rr.normal;
+ against_shape=rr.shape;
+ } else {
+ collided=false;
}
}
+void RayCast2D::force_raycast_update() {
+ _update_raycast_state();
+}
+
void RayCast2D::add_exception_rid(const RID& p_rid) {
exclude.insert(p_rid);
@@ -265,6 +270,7 @@ void RayCast2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_cast_to"),&RayCast2D::get_cast_to);
ObjectTypeDB::bind_method(_MD("is_colliding"),&RayCast2D::is_colliding);
+ ObjectTypeDB::bind_method(_MD("force_raycast_update"),&RayCast2D::force_raycast_update);
ObjectTypeDB::bind_method(_MD("get_collider"),&RayCast2D::get_collider);
ObjectTypeDB::bind_method(_MD("get_collider_shape"),&RayCast2D::get_collider_shape);
diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h
index e1caa8b63e..9bdcc2e199 100644
--- a/scene/2d/ray_cast_2d.h
+++ b/scene/2d/ray_cast_2d.h
@@ -52,6 +52,7 @@ class RayCast2D : public Node2D {
protected:
void _notification(int p_what);
+ void _update_raycast_state();
static void _bind_methods();
public:
@@ -70,6 +71,8 @@ public:
void set_exclude_parent_body(bool p_exclude_parent_body);
bool get_exclude_parent_body() const;
+ void force_raycast_update();
+
bool is_colliding() const;
Object *get_collider() const;
int get_collider_shape() const;