Add type mask property to RayCast2D
This commit is contained in:
parent
aad2bbdb6f
commit
793c53122a
2 changed files with 20 additions and 1 deletions
|
@ -53,6 +53,16 @@ uint32_t RayCast2D::get_layer_mask() const {
|
||||||
return layer_mask;
|
return layer_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RayCast2D::set_type_mask(uint32_t p_mask) {
|
||||||
|
|
||||||
|
type_mask=p_mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RayCast2D::get_type_mask() const {
|
||||||
|
|
||||||
|
return type_mask;
|
||||||
|
}
|
||||||
|
|
||||||
bool RayCast2D::is_colliding() const{
|
bool RayCast2D::is_colliding() const{
|
||||||
|
|
||||||
return collided;
|
return collided;
|
||||||
|
@ -162,7 +172,7 @@ void RayCast2D::_notification(int p_what) {
|
||||||
|
|
||||||
Physics2DDirectSpaceState::RayResult rr;
|
Physics2DDirectSpaceState::RayResult rr;
|
||||||
|
|
||||||
if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask)) {
|
if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask,type_mask)) {
|
||||||
|
|
||||||
collided=true;
|
collided=true;
|
||||||
against=rr.collider_id;
|
against=rr.collider_id;
|
||||||
|
@ -241,9 +251,13 @@ void RayCast2D::_bind_methods() {
|
||||||
ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&RayCast2D::set_layer_mask);
|
ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&RayCast2D::set_layer_mask);
|
||||||
ObjectTypeDB::bind_method(_MD("get_layer_mask"),&RayCast2D::get_layer_mask);
|
ObjectTypeDB::bind_method(_MD("get_layer_mask"),&RayCast2D::get_layer_mask);
|
||||||
|
|
||||||
|
ObjectTypeDB::bind_method(_MD("set_type_mask","mask"),&RayCast2D::set_type_mask);
|
||||||
|
ObjectTypeDB::bind_method(_MD("get_type_mask"),&RayCast2D::get_type_mask);
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled"));
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled"));
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"cast_to"),_SCS("set_cast_to"),_SCS("get_cast_to"));
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"cast_to"),_SCS("set_cast_to"),_SCS("get_cast_to"));
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT,"layer_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
|
ADD_PROPERTY(PropertyInfo(Variant::INT,"layer_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::INT,"type_mask",PROPERTY_HINT_FLAGS,"Static,Kinematic,Rigid,Character,Area"),_SCS("set_type_mask"),_SCS("get_type_mask"));
|
||||||
}
|
}
|
||||||
|
|
||||||
RayCast2D::RayCast2D() {
|
RayCast2D::RayCast2D() {
|
||||||
|
@ -253,5 +267,6 @@ RayCast2D::RayCast2D() {
|
||||||
collided=false;
|
collided=false;
|
||||||
against_shape=0;
|
against_shape=0;
|
||||||
layer_mask=1;
|
layer_mask=1;
|
||||||
|
type_mask=Physics2DDirectSpaceState::TYPE_MASK_COLLISION;
|
||||||
cast_to=Vector2(0,50);
|
cast_to=Vector2(0,50);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ class RayCast2D : public Node2D {
|
||||||
Vector2 collision_normal;
|
Vector2 collision_normal;
|
||||||
Set<RID> exclude;
|
Set<RID> exclude;
|
||||||
uint32_t layer_mask;
|
uint32_t layer_mask;
|
||||||
|
uint32_t type_mask;
|
||||||
|
|
||||||
|
|
||||||
Vector2 cast_to;
|
Vector2 cast_to;
|
||||||
|
@ -62,6 +63,9 @@ public:
|
||||||
void set_layer_mask(uint32_t p_mask);
|
void set_layer_mask(uint32_t p_mask);
|
||||||
uint32_t get_layer_mask() const;
|
uint32_t get_layer_mask() const;
|
||||||
|
|
||||||
|
void set_type_mask(uint32_t p_mask);
|
||||||
|
uint32_t get_type_mask() const;
|
||||||
|
|
||||||
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…
Reference in a new issue