ray_cast_2d.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #ifndef RAY_CAST_2D_H
  31. #define RAY_CAST_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class CollisionObject2D;
  34. class RayCast2D : public Node2D {
  35. GDCLASS(RayCast2D, Node2D);
  36. bool enabled = true;
  37. bool collided = false;
  38. ObjectID against;
  39. RID against_rid;
  40. int against_shape = 0;
  41. Vector2 collision_point;
  42. Vector2 collision_normal;
  43. HashSet<RID> exclude;
  44. uint32_t collision_mask = 1;
  45. bool exclude_parent_body = true;
  46. Vector2 target_position = Vector2(0, 50);
  47. bool collide_with_areas = false;
  48. bool collide_with_bodies = true;
  49. bool hit_from_inside = false;
  50. void _draw_debug_shape();
  51. protected:
  52. void _notification(int p_what);
  53. void _update_raycast_state();
  54. static void _bind_methods();
  55. public:
  56. void set_collide_with_areas(bool p_clip);
  57. bool is_collide_with_areas_enabled() const;
  58. void set_collide_with_bodies(bool p_clip);
  59. bool is_collide_with_bodies_enabled() const;
  60. void set_hit_from_inside(bool p_enable);
  61. bool is_hit_from_inside_enabled() const;
  62. void set_enabled(bool p_enabled);
  63. bool is_enabled() const;
  64. void set_target_position(const Vector2 &p_point);
  65. Vector2 get_target_position() const;
  66. void set_collision_mask(uint32_t p_mask);
  67. uint32_t get_collision_mask() const;
  68. void set_collision_mask_value(int p_layer_number, bool p_value);
  69. bool get_collision_mask_value(int p_layer_number) const;
  70. void set_exclude_parent_body(bool p_exclude_parent_body);
  71. bool get_exclude_parent_body() const;
  72. void force_raycast_update();
  73. bool is_colliding() const;
  74. Object *get_collider() const;
  75. RID get_collider_rid() const;
  76. int get_collider_shape() const;
  77. Vector2 get_collision_point() const;
  78. Vector2 get_collision_normal() const;
  79. void add_exception_rid(const RID &p_rid);
  80. void add_exception(const CollisionObject2D *p_node);
  81. void remove_exception_rid(const RID &p_rid);
  82. void remove_exception(const CollisionObject2D *p_node);
  83. void clear_exceptions();
  84. RayCast2D();
  85. };
  86. #endif // RAY_CAST_2D_H