Added force_raycast_update GDScript method for RayCast[2D]
This commit is contained in:
parent
1d2743302f
commit
7494a8c3c6
4 changed files with 71 additions and 54 deletions
|
@ -187,13 +187,19 @@ void RayCast2D::_notification(int p_what) {
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
_update_raycast_state();
|
||||||
|
|
||||||
|
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RayCast2D::_update_raycast_state() {
|
||||||
Ref<World2D> w2d = get_world_2d();
|
Ref<World2D> w2d = get_world_2d();
|
||||||
ERR_BREAK( w2d.is_null() );
|
ERR_FAIL_COND( w2d.is_null() );
|
||||||
|
|
||||||
Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(w2d->get_space());
|
Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(w2d->get_space());
|
||||||
ERR_BREAK( !dss );
|
ERR_FAIL_COND( !dss );
|
||||||
|
|
||||||
Matrix32 gt = get_global_transform();
|
Matrix32 gt = get_global_transform();
|
||||||
|
|
||||||
|
@ -213,11 +219,10 @@ void RayCast2D::_notification(int p_what) {
|
||||||
} else {
|
} else {
|
||||||
collided=false;
|
collided=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RayCast2D::force_raycast_update() {
|
||||||
|
_update_raycast_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayCast2D::add_exception_rid(const RID& p_rid) {
|
void RayCast2D::add_exception_rid(const RID& 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("get_cast_to"),&RayCast2D::get_cast_to);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("is_colliding"),&RayCast2D::is_colliding);
|
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"),&RayCast2D::get_collider);
|
||||||
ObjectTypeDB::bind_method(_MD("get_collider_shape"),&RayCast2D::get_collider_shape);
|
ObjectTypeDB::bind_method(_MD("get_collider_shape"),&RayCast2D::get_collider_shape);
|
||||||
|
|
|
@ -52,6 +52,7 @@ class RayCast2D : public Node2D {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
void _update_raycast_state();
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -70,6 +71,8 @@ public:
|
||||||
void set_exclude_parent_body(bool p_exclude_parent_body);
|
void set_exclude_parent_body(bool p_exclude_parent_body);
|
||||||
bool get_exclude_parent_body() const;
|
bool get_exclude_parent_body() const;
|
||||||
|
|
||||||
|
void force_raycast_update();
|
||||||
|
|
||||||
bool is_colliding() const;
|
bool is_colliding() const;
|
||||||
Object *get_collider() const;
|
Object *get_collider() const;
|
||||||
int get_collider_shape() const;
|
int get_collider_shape() const;
|
||||||
|
|
|
@ -134,13 +134,19 @@ void RayCast::_notification(int p_what) {
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
_update_raycast_state();
|
||||||
|
|
||||||
|
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RayCast::_update_raycast_state(){
|
||||||
Ref<World> w3d = get_world();
|
Ref<World> w3d = get_world();
|
||||||
ERR_BREAK( w3d.is_null() );
|
ERR_FAIL_COND( w3d.is_null() );
|
||||||
|
|
||||||
PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(w3d->get_space());
|
PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(w3d->get_space());
|
||||||
ERR_BREAK( !dss );
|
ERR_FAIL_COND( !dss );
|
||||||
|
|
||||||
Transform gt = get_global_transform();
|
Transform gt = get_global_transform();
|
||||||
|
|
||||||
|
@ -160,11 +166,10 @@ void RayCast::_notification(int p_what) {
|
||||||
} else {
|
} else {
|
||||||
collided=false;
|
collided=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RayCast::force_raycast_update() {
|
||||||
|
_update_raycast_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayCast::add_exception_rid(const RID& p_rid) {
|
void RayCast::add_exception_rid(const RID& p_rid) {
|
||||||
|
@ -212,6 +217,7 @@ void RayCast::_bind_methods() {
|
||||||
ObjectTypeDB::bind_method(_MD("get_cast_to"),&RayCast::get_cast_to);
|
ObjectTypeDB::bind_method(_MD("get_cast_to"),&RayCast::get_cast_to);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("is_colliding"),&RayCast::is_colliding);
|
ObjectTypeDB::bind_method(_MD("is_colliding"),&RayCast::is_colliding);
|
||||||
|
ObjectTypeDB::bind_method(_MD("force_raycast_update"),&RayCast::force_raycast_update);
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("get_collider"),&RayCast::get_collider);
|
ObjectTypeDB::bind_method(_MD("get_collider"),&RayCast::get_collider);
|
||||||
ObjectTypeDB::bind_method(_MD("get_collider_shape"),&RayCast::get_collider_shape);
|
ObjectTypeDB::bind_method(_MD("get_collider_shape"),&RayCast::get_collider_shape);
|
||||||
|
|
|
@ -53,6 +53,7 @@ class RayCast : public Spatial {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
void _update_raycast_state();
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -68,6 +69,7 @@ public:
|
||||||
void set_type_mask(uint32_t p_mask);
|
void set_type_mask(uint32_t p_mask);
|
||||||
uint32_t get_type_mask() const;
|
uint32_t get_type_mask() const;
|
||||||
|
|
||||||
|
void force_raycast_update();
|
||||||
bool is_colliding() const;
|
bool is_colliding() const;
|
||||||
Object *get_collider() const;
|
Object *get_collider() const;
|
||||||
int get_collider_shape() const;
|
int get_collider_shape() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue