| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
|
| 35 |
class CollisionObject2D; |
| 36 |
|
| 37 |
class RayCast2D : public Node2D { |
| 38 |
GDCLASS(RayCast2D, Node2D); |
| 39 |
|
| 40 |
bool enabled = true; |
| 41 |
bool collided = false; |
| 42 |
ObjectID against; |
| 43 |
RID against_rid; |
| 44 |
int against_shape = 0; |
| 45 |
Vector2 collision_point; |
| 46 |
Vector2 collision_normal; |
| 47 |
HashSet<RID> exclude; |
| 48 |
uint32_t collision_mask = 1; |
| 49 |
bool exclude_parent_body = true; |
| 50 |
|
| 51 |
Vector2 target_position = Vector2(0, 50); |
| 52 |
|
| 53 |
bool collide_with_areas = false; |
| 54 |
bool collide_with_bodies = true; |
| 55 |
|
| 56 |
bool hit_from_inside = false; |
| 57 |
|
| 58 |
void _draw_debug_shape(); |
| 59 |
|
| 60 |
protected: |
| 61 |
void _notification(int p_what); |
| 62 |
void _update_raycast_state(); |
| 63 |
static void _bind_methods(); |
| 64 |
|
| 65 |
public: |
| 66 |
void set_collide_with_areas(bool p_clip); |
| 67 |
bool is_collide_with_areas_enabled() const; |
| 68 |
|
| 69 |
void set_collide_with_bodies(bool p_clip); |
| 70 |
bool is_collide_with_bodies_enabled() const; |
| 71 |
|
| 72 |
void set_hit_from_inside(bool p_enable); |
| 73 |
bool is_hit_from_inside_enabled() const; |
| 74 |
|
| 75 |
void set_enabled(bool p_enabled); |
| 76 |
bool is_enabled() const; |
| 77 |
|
| 78 |
void set_target_position(const Vector2 &p_point); |
| 79 |
Vector2 get_target_position() const; |
| 80 |
|
| 81 |
void set_collision_mask(uint32_t p_mask); |
| 82 |
uint32_t get_collision_mask() const; |
| 83 |
|
| 84 |
void set_collision_mask_value(int p_layer_number, bool p_value); |
| 85 |
bool get_collision_mask_value(int p_layer_number) const; |
| 86 |
|
| 87 |
void set_exclude_parent_body(bool p_exclude_parent_body); |
| 88 |
bool get_exclude_parent_body() const; |
| 89 |
|
| 90 |
void force_raycast_update(); |
| 91 |
|
| 92 |
bool is_colliding() const; |
| 93 |
Object *get_collider() const; |
| 94 |
RID get_collider_rid() const; |
| 95 |
int get_collider_shape() const; |
| 96 |
Vector2 get_collision_point() const; |
| 97 |
Vector2 get_collision_normal() const; |
| 98 |
|
| 99 |
void add_exception_rid(const RID &p_rid); |
| 100 |
void add_exception(RequiredParam<const CollisionObject2D> rp_node); |
| 101 |
void remove_exception_rid(const RID &p_rid); |
| 102 |
void remove_exception(RequiredParam<const CollisionObject2D> rp_node); |
| 103 |
void clear_exceptions(); |
| 104 |
|
| 105 |
RayCast2D(); |
| 106 |
}; |