Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/2d/physics/shape_cast_2d.h
9906 views
1
/**************************************************************************/
2
/* shape_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
#pragma once
32
33
#include "scene/2d/node_2d.h"
34
#include "scene/resources/2d/shape_2d.h"
35
#include "servers/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
// Result
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(const CollisionObject2D *p_node);
116
void remove_exception_rid(const RID &p_rid);
117
void remove_exception(const CollisionObject2D *p_node);
118
void clear_exceptions();
119
120
PackedStringArray get_configuration_warnings() const override;
121
122
ShapeCast2D();
123
};
124
125