1 /*************************************************************************/ 2 /* ray_cast_2d.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ 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 #ifndef RAY_CAST_2D_H 31 #define RAY_CAST_2D_H 32 33 #include "scene/2d/node_2d.h" 34 35 class RayCast2D : public Node2D { 36 37 OBJ_TYPE(RayCast2D, Node2D); 38 39 bool enabled; 40 bool collided; 41 ObjectID against; 42 int against_shape; 43 Vector2 collision_point; 44 Vector2 collision_normal; 45 Set<RID> exclude; 46 uint32_t layer_mask; 47 uint32_t type_mask; 48 49 Vector2 cast_to; 50 51 protected: 52 void _notification(int p_what); 53 void _update_raycast_state(); 54 static void _bind_methods(); 55 56 public: 57 void set_enabled(bool p_enabled); 58 bool is_enabled() const; 59 60 void set_cast_to(const Vector2 &p_point); 61 Vector2 get_cast_to() const; 62 63 void set_layer_mask(uint32_t p_mask); 64 uint32_t get_layer_mask() const; 65 66 void set_type_mask(uint32_t p_mask); 67 uint32_t get_type_mask() const; 68 69 void force_raycast_update(); 70 71 bool is_colliding() const; 72 Object *get_collider() const; 73 int get_collider_shape() const; 74 Vector2 get_collision_point() const; 75 Vector2 get_collision_normal() const; 76 77 void add_exception_rid(const RID &p_rid); 78 void add_exception(const Object *p_object); 79 void remove_exception_rid(const RID &p_rid); 80 void remove_exception(const Object *p_object); 81 void clear_exceptions(); 82 83 RayCast2D(); 84 }; 85 86 #endif // RAY_CAST_2D_H 87