1 | /**************************************************************************/ |
2 | /* ray_cast_2d.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef RAY_CAST_2D_H |
32 | #define RAY_CAST_2D_H |
33 | |
34 | #include "scene/2d/node_2d.h" |
35 | |
36 | class CollisionObject2D; |
37 | |
38 | class RayCast2D : public Node2D { |
39 | GDCLASS(RayCast2D, Node2D); |
40 | |
41 | bool enabled = true; |
42 | bool collided = false; |
43 | ObjectID against; |
44 | RID against_rid; |
45 | int against_shape = 0; |
46 | Vector2 collision_point; |
47 | Vector2 collision_normal; |
48 | HashSet<RID> exclude; |
49 | uint32_t collision_mask = 1; |
50 | bool exclude_parent_body = true; |
51 | |
52 | Vector2 target_position = Vector2(0, 50); |
53 | |
54 | bool collide_with_areas = false; |
55 | bool collide_with_bodies = true; |
56 | |
57 | bool hit_from_inside = false; |
58 | |
59 | void _draw_debug_shape(); |
60 | |
61 | protected: |
62 | void _notification(int p_what); |
63 | void _update_raycast_state(); |
64 | static void _bind_methods(); |
65 | |
66 | public: |
67 | void set_collide_with_areas(bool p_clip); |
68 | bool is_collide_with_areas_enabled() const; |
69 | |
70 | void set_collide_with_bodies(bool p_clip); |
71 | bool is_collide_with_bodies_enabled() const; |
72 | |
73 | void set_hit_from_inside(bool p_enable); |
74 | bool is_hit_from_inside_enabled() const; |
75 | |
76 | void set_enabled(bool p_enabled); |
77 | bool is_enabled() const; |
78 | |
79 | void set_target_position(const Vector2 &p_point); |
80 | Vector2 get_target_position() const; |
81 | |
82 | void set_collision_mask(uint32_t p_mask); |
83 | uint32_t get_collision_mask() const; |
84 | |
85 | void set_collision_mask_value(int p_layer_number, bool p_value); |
86 | bool get_collision_mask_value(int p_layer_number) const; |
87 | |
88 | void set_exclude_parent_body(bool p_exclude_parent_body); |
89 | bool get_exclude_parent_body() const; |
90 | |
91 | void force_raycast_update(); |
92 | |
93 | bool is_colliding() const; |
94 | Object *get_collider() const; |
95 | RID get_collider_rid() const; |
96 | int get_collider_shape() const; |
97 | Vector2 get_collision_point() const; |
98 | Vector2 get_collision_normal() const; |
99 | |
100 | void add_exception_rid(const RID &p_rid); |
101 | void add_exception(const CollisionObject2D *p_node); |
102 | void remove_exception_rid(const RID &p_rid); |
103 | void remove_exception(const CollisionObject2D *p_node); |
104 | void clear_exceptions(); |
105 | |
106 | RayCast2D(); |
107 | }; |
108 | |
109 | #endif // RAY_CAST_2D_H |
110 | |