collision_object_2d.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /**************************************************************************/
  2. /* collision_object_2d.cpp */
  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. #include "collision_object_2d.h"
  31. #include "scene/scene_string_names.h"
  32. #include "servers/physics_2d_server.h"
  33. void CollisionObject2D::_notification(int p_what) {
  34. switch (p_what) {
  35. case NOTIFICATION_ENTER_TREE: {
  36. Transform2D global_transform = get_global_transform();
  37. if (area) {
  38. Physics2DServer::get_singleton()->area_set_transform(rid, global_transform);
  39. } else {
  40. Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
  41. }
  42. Ref<World2D> world_ref = get_world_2d();
  43. ERR_FAIL_COND(!world_ref.is_valid());
  44. RID space = world_ref->get_space();
  45. if (area) {
  46. Physics2DServer::get_singleton()->area_set_space(rid, space);
  47. } else {
  48. Physics2DServer::get_singleton()->body_set_space(rid, space);
  49. }
  50. _update_pickable();
  51. //get space
  52. } break;
  53. case NOTIFICATION_ENTER_CANVAS: {
  54. if (area) {
  55. Physics2DServer::get_singleton()->area_attach_canvas_instance_id(rid, get_canvas_layer_instance_id());
  56. } else {
  57. Physics2DServer::get_singleton()->body_attach_canvas_instance_id(rid, get_canvas_layer_instance_id());
  58. }
  59. } break;
  60. case NOTIFICATION_VISIBILITY_CHANGED: {
  61. _update_pickable();
  62. } break;
  63. case NOTIFICATION_TRANSFORM_CHANGED: {
  64. if (only_update_transform_changes) {
  65. return;
  66. }
  67. Transform2D global_transform = get_global_transform();
  68. if (area) {
  69. Physics2DServer::get_singleton()->area_set_transform(rid, global_transform);
  70. } else {
  71. Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
  72. }
  73. } break;
  74. case NOTIFICATION_EXIT_TREE: {
  75. if (area) {
  76. Physics2DServer::get_singleton()->area_set_space(rid, RID());
  77. } else {
  78. Physics2DServer::get_singleton()->body_set_space(rid, RID());
  79. }
  80. } break;
  81. case NOTIFICATION_EXIT_CANVAS: {
  82. if (area) {
  83. Physics2DServer::get_singleton()->area_attach_canvas_instance_id(rid, 0);
  84. } else {
  85. Physics2DServer::get_singleton()->body_attach_canvas_instance_id(rid, 0);
  86. }
  87. } break;
  88. }
  89. }
  90. void CollisionObject2D::set_collision_layer(uint32_t p_layer) {
  91. collision_layer = p_layer;
  92. if (area) {
  93. Physics2DServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer);
  94. } else {
  95. Physics2DServer::get_singleton()->body_set_collision_layer(get_rid(), p_layer);
  96. }
  97. }
  98. uint32_t CollisionObject2D::get_collision_layer() const {
  99. return collision_layer;
  100. }
  101. void CollisionObject2D::set_collision_mask(uint32_t p_mask) {
  102. collision_mask = p_mask;
  103. if (area) {
  104. Physics2DServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask);
  105. } else {
  106. Physics2DServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask);
  107. }
  108. }
  109. uint32_t CollisionObject2D::get_collision_mask() const {
  110. return collision_mask;
  111. }
  112. void CollisionObject2D::set_collision_layer_bit(int p_bit, bool p_value) {
  113. ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision layer bit must be between 0 and 31 inclusive.");
  114. uint32_t collision_layer = get_collision_layer();
  115. if (p_value) {
  116. collision_layer |= 1 << p_bit;
  117. } else {
  118. collision_layer &= ~(1 << p_bit);
  119. }
  120. set_collision_layer(collision_layer);
  121. }
  122. bool CollisionObject2D::get_collision_layer_bit(int p_bit) const {
  123. ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision layer bit must be between 0 and 31 inclusive.");
  124. return get_collision_layer() & (1 << p_bit);
  125. }
  126. void CollisionObject2D::set_collision_mask_bit(int p_bit, bool p_value) {
  127. ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision mask bit must be between 0 and 31 inclusive.");
  128. uint32_t mask = get_collision_mask();
  129. if (p_value) {
  130. mask |= 1 << p_bit;
  131. } else {
  132. mask &= ~(1 << p_bit);
  133. }
  134. set_collision_mask(mask);
  135. }
  136. bool CollisionObject2D::get_collision_mask_bit(int p_bit) const {
  137. ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision mask bit must be between 0 and 31 inclusive.");
  138. return get_collision_mask() & (1 << p_bit);
  139. }
  140. uint32_t CollisionObject2D::create_shape_owner(Object *p_owner) {
  141. ShapeData sd;
  142. uint32_t id;
  143. if (shapes.size() == 0) {
  144. id = 0;
  145. } else {
  146. id = shapes.back()->key() + 1;
  147. }
  148. sd.owner_id = p_owner ? p_owner->get_instance_id() : 0;
  149. shapes[id] = sd;
  150. return id;
  151. }
  152. void CollisionObject2D::remove_shape_owner(uint32_t owner) {
  153. ERR_FAIL_COND(!shapes.has(owner));
  154. shape_owner_clear_shapes(owner);
  155. shapes.erase(owner);
  156. }
  157. void CollisionObject2D::shape_owner_set_disabled(uint32_t p_owner, bool p_disabled) {
  158. ERR_FAIL_COND(!shapes.has(p_owner));
  159. ShapeData &sd = shapes[p_owner];
  160. sd.disabled = p_disabled;
  161. for (int i = 0; i < sd.shapes.size(); i++) {
  162. if (area) {
  163. Physics2DServer::get_singleton()->area_set_shape_disabled(rid, sd.shapes[i].index, p_disabled);
  164. } else {
  165. Physics2DServer::get_singleton()->body_set_shape_disabled(rid, sd.shapes[i].index, p_disabled);
  166. }
  167. }
  168. }
  169. bool CollisionObject2D::is_shape_owner_disabled(uint32_t p_owner) const {
  170. ERR_FAIL_COND_V(!shapes.has(p_owner), false);
  171. return shapes[p_owner].disabled;
  172. }
  173. void CollisionObject2D::shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable) {
  174. if (area) {
  175. return; //not for areas
  176. }
  177. ERR_FAIL_COND(!shapes.has(p_owner));
  178. ShapeData &sd = shapes[p_owner];
  179. sd.one_way_collision = p_enable;
  180. for (int i = 0; i < sd.shapes.size(); i++) {
  181. Physics2DServer::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, sd.one_way_collision, sd.one_way_collision_margin);
  182. }
  183. }
  184. bool CollisionObject2D::is_shape_owner_one_way_collision_enabled(uint32_t p_owner) const {
  185. ERR_FAIL_COND_V(!shapes.has(p_owner), false);
  186. return shapes[p_owner].one_way_collision;
  187. }
  188. void CollisionObject2D::shape_owner_set_one_way_collision_margin(uint32_t p_owner, float p_margin) {
  189. if (area) {
  190. return; //not for areas
  191. }
  192. ERR_FAIL_COND(!shapes.has(p_owner));
  193. ShapeData &sd = shapes[p_owner];
  194. sd.one_way_collision_margin = p_margin;
  195. for (int i = 0; i < sd.shapes.size(); i++) {
  196. Physics2DServer::get_singleton()->body_set_shape_as_one_way_collision(rid, sd.shapes[i].index, sd.one_way_collision, sd.one_way_collision_margin);
  197. }
  198. }
  199. float CollisionObject2D::get_shape_owner_one_way_collision_margin(uint32_t p_owner) const {
  200. ERR_FAIL_COND_V(!shapes.has(p_owner), 0);
  201. return shapes[p_owner].one_way_collision_margin;
  202. }
  203. void CollisionObject2D::get_shape_owners(List<uint32_t> *r_owners) {
  204. for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) {
  205. r_owners->push_back(E->key());
  206. }
  207. }
  208. Array CollisionObject2D::_get_shape_owners() {
  209. Array ret;
  210. for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) {
  211. ret.push_back(E->key());
  212. }
  213. return ret;
  214. }
  215. void CollisionObject2D::shape_owner_set_transform(uint32_t p_owner, const Transform2D &p_transform) {
  216. ERR_FAIL_COND(!shapes.has(p_owner));
  217. ShapeData &sd = shapes[p_owner];
  218. sd.xform = p_transform;
  219. for (int i = 0; i < sd.shapes.size(); i++) {
  220. if (area) {
  221. Physics2DServer::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, sd.xform);
  222. } else {
  223. Physics2DServer::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, sd.xform);
  224. }
  225. }
  226. }
  227. Transform2D CollisionObject2D::shape_owner_get_transform(uint32_t p_owner) const {
  228. ERR_FAIL_COND_V(!shapes.has(p_owner), Transform2D());
  229. return shapes[p_owner].xform;
  230. }
  231. Object *CollisionObject2D::shape_owner_get_owner(uint32_t p_owner) const {
  232. ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr);
  233. return ObjectDB::get_instance(shapes[p_owner].owner_id);
  234. }
  235. void CollisionObject2D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape) {
  236. ERR_FAIL_COND(!shapes.has(p_owner));
  237. ERR_FAIL_COND(p_shape.is_null());
  238. ShapeData &sd = shapes[p_owner];
  239. ShapeData::Shape s;
  240. s.index = total_subshapes;
  241. s.shape = p_shape;
  242. if (area) {
  243. Physics2DServer::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled);
  244. } else {
  245. Physics2DServer::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled);
  246. }
  247. sd.shapes.push_back(s);
  248. total_subshapes++;
  249. }
  250. int CollisionObject2D::shape_owner_get_shape_count(uint32_t p_owner) const {
  251. ERR_FAIL_COND_V(!shapes.has(p_owner), 0);
  252. return shapes[p_owner].shapes.size();
  253. }
  254. Ref<Shape2D> CollisionObject2D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const {
  255. ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape2D>());
  256. ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape2D>());
  257. return shapes[p_owner].shapes[p_shape].shape;
  258. }
  259. int CollisionObject2D::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const {
  260. ERR_FAIL_COND_V(!shapes.has(p_owner), -1);
  261. ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), -1);
  262. return shapes[p_owner].shapes[p_shape].index;
  263. }
  264. void CollisionObject2D::shape_owner_remove_shape(uint32_t p_owner, int p_shape) {
  265. ERR_FAIL_COND(!shapes.has(p_owner));
  266. ERR_FAIL_INDEX(p_shape, shapes[p_owner].shapes.size());
  267. int index_to_remove = shapes[p_owner].shapes[p_shape].index;
  268. if (area) {
  269. Physics2DServer::get_singleton()->area_remove_shape(rid, index_to_remove);
  270. } else {
  271. Physics2DServer::get_singleton()->body_remove_shape(rid, index_to_remove);
  272. }
  273. shapes[p_owner].shapes.remove(p_shape);
  274. for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) {
  275. for (int i = 0; i < E->get().shapes.size(); i++) {
  276. if (E->get().shapes[i].index > index_to_remove) {
  277. E->get().shapes.write[i].index -= 1;
  278. }
  279. }
  280. }
  281. total_subshapes--;
  282. }
  283. void CollisionObject2D::shape_owner_clear_shapes(uint32_t p_owner) {
  284. ERR_FAIL_COND(!shapes.has(p_owner));
  285. while (shape_owner_get_shape_count(p_owner) > 0) {
  286. shape_owner_remove_shape(p_owner, 0);
  287. }
  288. }
  289. uint32_t CollisionObject2D::shape_find_owner(int p_shape_index) const {
  290. ERR_FAIL_INDEX_V(p_shape_index, total_subshapes, UINT32_MAX);
  291. for (const Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) {
  292. for (int i = 0; i < E->get().shapes.size(); i++) {
  293. if (E->get().shapes[i].index == p_shape_index) {
  294. return E->key();
  295. }
  296. }
  297. }
  298. //in theory it should be unreachable
  299. ERR_FAIL_V_MSG(UINT32_MAX, "Can't find owner for shape index " + itos(p_shape_index) + ".");
  300. }
  301. void CollisionObject2D::set_pickable(bool p_enabled) {
  302. if (pickable == p_enabled) {
  303. return;
  304. }
  305. pickable = p_enabled;
  306. _update_pickable();
  307. }
  308. bool CollisionObject2D::is_pickable() const {
  309. return pickable;
  310. }
  311. void CollisionObject2D::_input_event(Node *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape) {
  312. if (get_script_instance()) {
  313. get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_viewport, p_input_event, p_shape);
  314. }
  315. emit_signal(SceneStringNames::get_singleton()->input_event, p_viewport, p_input_event, p_shape);
  316. }
  317. void CollisionObject2D::_mouse_enter() {
  318. if (get_script_instance()) {
  319. get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_enter);
  320. }
  321. emit_signal(SceneStringNames::get_singleton()->mouse_entered);
  322. }
  323. void CollisionObject2D::_mouse_exit() {
  324. if (get_script_instance()) {
  325. get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit);
  326. }
  327. emit_signal(SceneStringNames::get_singleton()->mouse_exited);
  328. }
  329. void CollisionObject2D::set_only_update_transform_changes(bool p_enable) {
  330. only_update_transform_changes = p_enable;
  331. }
  332. void CollisionObject2D::_update_pickable() {
  333. if (!is_inside_tree()) {
  334. return;
  335. }
  336. bool is_pickable = pickable && is_visible_in_tree();
  337. if (area) {
  338. Physics2DServer::get_singleton()->area_set_pickable(rid, is_pickable);
  339. } else {
  340. Physics2DServer::get_singleton()->body_set_pickable(rid, is_pickable);
  341. }
  342. }
  343. String CollisionObject2D::get_configuration_warning() const {
  344. String warning = Node2D::get_configuration_warning();
  345. if (shapes.empty()) {
  346. if (!warning.empty()) {
  347. warning += "\n\n";
  348. }
  349. warning += TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape2D or CollisionPolygon2D as a child to define its shape.");
  350. }
  351. return warning;
  352. }
  353. void CollisionObject2D::_bind_methods() {
  354. ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject2D::get_rid);
  355. ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &CollisionObject2D::set_collision_layer);
  356. ClassDB::bind_method(D_METHOD("get_collision_layer"), &CollisionObject2D::get_collision_layer);
  357. ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &CollisionObject2D::set_collision_mask);
  358. ClassDB::bind_method(D_METHOD("get_collision_mask"), &CollisionObject2D::get_collision_mask);
  359. ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &CollisionObject2D::set_collision_layer_bit);
  360. ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &CollisionObject2D::get_collision_layer_bit);
  361. ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &CollisionObject2D::set_collision_mask_bit);
  362. ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &CollisionObject2D::get_collision_mask_bit);
  363. ClassDB::bind_method(D_METHOD("set_pickable", "enabled"), &CollisionObject2D::set_pickable);
  364. ClassDB::bind_method(D_METHOD("is_pickable"), &CollisionObject2D::is_pickable);
  365. ClassDB::bind_method(D_METHOD("create_shape_owner", "owner"), &CollisionObject2D::create_shape_owner);
  366. ClassDB::bind_method(D_METHOD("remove_shape_owner", "owner_id"), &CollisionObject2D::remove_shape_owner);
  367. ClassDB::bind_method(D_METHOD("get_shape_owners"), &CollisionObject2D::_get_shape_owners);
  368. ClassDB::bind_method(D_METHOD("shape_owner_set_transform", "owner_id", "transform"), &CollisionObject2D::shape_owner_set_transform);
  369. ClassDB::bind_method(D_METHOD("shape_owner_get_transform", "owner_id"), &CollisionObject2D::shape_owner_get_transform);
  370. ClassDB::bind_method(D_METHOD("shape_owner_get_owner", "owner_id"), &CollisionObject2D::shape_owner_get_owner);
  371. ClassDB::bind_method(D_METHOD("shape_owner_set_disabled", "owner_id", "disabled"), &CollisionObject2D::shape_owner_set_disabled);
  372. ClassDB::bind_method(D_METHOD("is_shape_owner_disabled", "owner_id"), &CollisionObject2D::is_shape_owner_disabled);
  373. ClassDB::bind_method(D_METHOD("shape_owner_set_one_way_collision", "owner_id", "enable"), &CollisionObject2D::shape_owner_set_one_way_collision);
  374. ClassDB::bind_method(D_METHOD("is_shape_owner_one_way_collision_enabled", "owner_id"), &CollisionObject2D::is_shape_owner_one_way_collision_enabled);
  375. ClassDB::bind_method(D_METHOD("shape_owner_set_one_way_collision_margin", "owner_id", "margin"), &CollisionObject2D::shape_owner_set_one_way_collision_margin);
  376. ClassDB::bind_method(D_METHOD("get_shape_owner_one_way_collision_margin", "owner_id"), &CollisionObject2D::get_shape_owner_one_way_collision_margin);
  377. ClassDB::bind_method(D_METHOD("shape_owner_add_shape", "owner_id", "shape"), &CollisionObject2D::shape_owner_add_shape);
  378. ClassDB::bind_method(D_METHOD("shape_owner_get_shape_count", "owner_id"), &CollisionObject2D::shape_owner_get_shape_count);
  379. ClassDB::bind_method(D_METHOD("shape_owner_get_shape", "owner_id", "shape_id"), &CollisionObject2D::shape_owner_get_shape);
  380. ClassDB::bind_method(D_METHOD("shape_owner_get_shape_index", "owner_id", "shape_id"), &CollisionObject2D::shape_owner_get_shape_index);
  381. ClassDB::bind_method(D_METHOD("shape_owner_remove_shape", "owner_id", "shape_id"), &CollisionObject2D::shape_owner_remove_shape);
  382. ClassDB::bind_method(D_METHOD("shape_owner_clear_shapes", "owner_id"), &CollisionObject2D::shape_owner_clear_shapes);
  383. ClassDB::bind_method(D_METHOD("shape_find_owner", "shape_index"), &CollisionObject2D::shape_find_owner);
  384. BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::INT, "shape_idx")));
  385. ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "viewport", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::INT, "shape_idx")));
  386. ADD_SIGNAL(MethodInfo("mouse_entered"));
  387. ADD_SIGNAL(MethodInfo("mouse_exited"));
  388. ADD_GROUP("Collision", "collision_");
  389. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer");
  390. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask");
  391. ADD_GROUP("Input", "input_");
  392. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_pickable"), "set_pickable", "is_pickable");
  393. }
  394. CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) {
  395. rid = p_rid;
  396. area = p_area;
  397. pickable = true;
  398. set_notify_transform(true);
  399. total_subshapes = 0;
  400. only_update_transform_changes = false;
  401. if (p_area) {
  402. Physics2DServer::get_singleton()->area_attach_object_instance_id(rid, get_instance_id());
  403. } else {
  404. Physics2DServer::get_singleton()->body_attach_object_instance_id(rid, get_instance_id());
  405. }
  406. }
  407. CollisionObject2D::CollisionObject2D() {
  408. //owner=
  409. set_notify_transform(true);
  410. }
  411. CollisionObject2D::~CollisionObject2D() {
  412. Physics2DServer::get_singleton()->free(rid);
  413. }