| 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 |
#include "scene/resources/2d/shape_2d.h" |
| 35 |
#include "servers/physics_2d/physics_server_2d.h" |
| 36 |
|
| 37 |
class CollisionObject2D; |
| 38 |
|
| 39 |
class ShapeCast2D : public Node2D { |
| 40 |
GDCLASS(ShapeCast2D, Node2D); |
| 41 |
|
| 42 |
bool enabled = true; |
| 43 |
|
| 44 |
Ref<Shape2D> shape; |
| 45 |
RID shape_rid; |
| 46 |
Vector2 target_position = Vector2(0, 50); |
| 47 |
|
| 48 |
HashSet<RID> exclude; |
| 49 |
real_t margin = 0.0; |
| 50 |
uint32_t collision_mask = 1; |
| 51 |
bool exclude_parent_body = true; |
| 52 |
bool collide_with_areas = false; |
| 53 |
bool collide_with_bodies = true; |
| 54 |
|
| 55 |
|
| 56 |
int max_results = 32; |
| 57 |
Vector<PhysicsDirectSpaceState2D::ShapeRestInfo> result; |
| 58 |
bool collided = false; |
| 59 |
real_t collision_safe_fraction = 1.0; |
| 60 |
real_t collision_unsafe_fraction = 1.0; |
| 61 |
|
| 62 |
void _shape_changed(); |
| 63 |
|
| 64 |
protected: |
| 65 |
void _notification(int p_what); |
| 66 |
void _update_shapecast_state(); |
| 67 |
static void _bind_methods(); |
| 68 |
|
| 69 |
public: |
| 70 |
void set_collide_with_areas(bool p_clip); |
| 71 |
bool is_collide_with_areas_enabled() const; |
| 72 |
|
| 73 |
void set_collide_with_bodies(bool p_clip); |
| 74 |
bool is_collide_with_bodies_enabled() const; |
| 75 |
|
| 76 |
void set_enabled(bool p_enabled); |
| 77 |
bool is_enabled() const; |
| 78 |
|
| 79 |
void set_shape(const Ref<Shape2D> &p_shape); |
| 80 |
Ref<Shape2D> get_shape() const; |
| 81 |
|
| 82 |
void set_target_position(const Vector2 &p_point); |
| 83 |
Vector2 get_target_position() const; |
| 84 |
|
| 85 |
void set_margin(real_t p_margin); |
| 86 |
real_t get_margin() const; |
| 87 |
|
| 88 |
void set_max_results(int p_max_results); |
| 89 |
int get_max_results() const; |
| 90 |
|
| 91 |
void set_collision_mask(uint32_t p_mask); |
| 92 |
uint32_t get_collision_mask() const; |
| 93 |
|
| 94 |
void set_collision_mask_value(int p_layer_number, bool p_value); |
| 95 |
bool get_collision_mask_value(int p_layer_number) const; |
| 96 |
|
| 97 |
void set_exclude_parent_body(bool p_exclude_parent_body); |
| 98 |
bool get_exclude_parent_body() const; |
| 99 |
|
| 100 |
void force_shapecast_update(); |
| 101 |
bool is_colliding() const; |
| 102 |
|
| 103 |
Array get_collision_result() const; |
| 104 |
int get_collision_count() const; |
| 105 |
Object *get_collider(int p_idx) const; |
| 106 |
RID get_collider_rid(int p_idx) const; |
| 107 |
int get_collider_shape(int p_idx) const; |
| 108 |
Vector2 get_collision_point(int p_idx) const; |
| 109 |
Vector2 get_collision_normal(int p_idx) const; |
| 110 |
|
| 111 |
real_t get_closest_collision_safe_fraction() const; |
| 112 |
real_t get_closest_collision_unsafe_fraction() const; |
| 113 |
|
| 114 |
void add_exception_rid(const RID &p_rid); |
| 115 |
void add_exception(RequiredParam<const CollisionObject2D> rp_node); |
| 116 |
void remove_exception_rid(const RID &p_rid); |
| 117 |
void remove_exception(RequiredParam<const CollisionObject2D> rp_node); |
| 118 |
void clear_exceptions(); |
| 119 |
|
| 120 |
PackedStringArray get_configuration_warnings() const override; |
| 121 |
|
| 122 |
ShapeCast2D(); |
| 123 |
}; |