physics_body.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /**************************************************************************/
  2. /* physics_body.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 PHYSICS_BODY_H
  31. #define PHYSICS_BODY_H
  32. #include "core/vset.h"
  33. #include "scene/3d/collision_object.h"
  34. #include "scene/resources/physics_material.h"
  35. #include "servers/physics_server.h"
  36. #include "skeleton.h"
  37. class PhysicsBody : public CollisionObject {
  38. GDCLASS(PhysicsBody, CollisionObject);
  39. void _set_layers(uint32_t p_mask);
  40. uint32_t _get_layers() const;
  41. protected:
  42. static void _bind_methods();
  43. void _notification(int p_what);
  44. PhysicsBody(PhysicsServer::BodyMode p_mode);
  45. public:
  46. virtual Vector3 get_linear_velocity() const;
  47. virtual Vector3 get_angular_velocity() const;
  48. virtual float get_inverse_mass() const;
  49. Array get_collision_exceptions();
  50. void add_collision_exception_with(Node *p_node); //must be physicsbody
  51. void remove_collision_exception_with(Node *p_node);
  52. };
  53. class StaticBody : public PhysicsBody {
  54. GDCLASS(StaticBody, PhysicsBody);
  55. Vector3 constant_linear_velocity;
  56. Vector3 constant_angular_velocity;
  57. Ref<PhysicsMaterial> physics_material_override;
  58. protected:
  59. static void _bind_methods();
  60. public:
  61. #ifndef DISABLE_DEPRECATED
  62. void set_friction(real_t p_friction);
  63. real_t get_friction() const;
  64. void set_bounce(real_t p_bounce);
  65. real_t get_bounce() const;
  66. #endif
  67. void set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override);
  68. Ref<PhysicsMaterial> get_physics_material_override() const;
  69. void set_constant_linear_velocity(const Vector3 &p_vel);
  70. void set_constant_angular_velocity(const Vector3 &p_vel);
  71. Vector3 get_constant_linear_velocity() const;
  72. Vector3 get_constant_angular_velocity() const;
  73. StaticBody();
  74. ~StaticBody();
  75. private:
  76. void _reload_physics_characteristics();
  77. };
  78. class RigidBody : public PhysicsBody {
  79. GDCLASS(RigidBody, PhysicsBody);
  80. public:
  81. enum Mode {
  82. MODE_RIGID,
  83. MODE_STATIC,
  84. MODE_CHARACTER,
  85. MODE_KINEMATIC,
  86. };
  87. protected:
  88. bool can_sleep;
  89. PhysicsDirectBodyState *state;
  90. Mode mode;
  91. real_t mass;
  92. Ref<PhysicsMaterial> physics_material_override;
  93. Vector3 linear_velocity;
  94. Vector3 angular_velocity;
  95. Basis inverse_inertia_tensor;
  96. real_t gravity_scale;
  97. real_t linear_damp;
  98. real_t angular_damp;
  99. bool sleeping;
  100. bool ccd;
  101. int max_contacts_reported;
  102. bool custom_integrator;
  103. struct ShapePair {
  104. int body_shape;
  105. int local_shape;
  106. bool tagged;
  107. bool operator<(const ShapePair &p_sp) const {
  108. if (body_shape == p_sp.body_shape) {
  109. return local_shape < p_sp.local_shape;
  110. } else {
  111. return body_shape < p_sp.body_shape;
  112. }
  113. }
  114. ShapePair() {}
  115. ShapePair(int p_bs, int p_ls) {
  116. body_shape = p_bs;
  117. local_shape = p_ls;
  118. tagged = false;
  119. }
  120. };
  121. struct RigidBody_RemoveAction {
  122. RID rid;
  123. ObjectID body_id;
  124. ShapePair pair;
  125. };
  126. struct BodyState {
  127. RID rid;
  128. bool in_tree;
  129. VSet<ShapePair> shapes;
  130. };
  131. struct ContactMonitor {
  132. bool locked;
  133. Map<ObjectID, BodyState> body_map;
  134. };
  135. ContactMonitor *contact_monitor;
  136. void _body_enter_tree(ObjectID p_id);
  137. void _body_exit_tree(ObjectID p_id);
  138. void _body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_local_shape);
  139. virtual void _direct_state_changed(Object *p_state);
  140. void _notification(int p_what);
  141. static void _bind_methods();
  142. public:
  143. void set_mode(Mode p_mode);
  144. Mode get_mode() const;
  145. void set_mass(real_t p_mass);
  146. real_t get_mass() const;
  147. virtual float get_inverse_mass() const { return 1.0 / mass; }
  148. void set_weight(real_t p_weight);
  149. real_t get_weight() const;
  150. #ifndef DISABLE_DEPRECATED
  151. void set_friction(real_t p_friction);
  152. real_t get_friction() const;
  153. void set_bounce(real_t p_bounce);
  154. real_t get_bounce() const;
  155. #endif
  156. void set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override);
  157. Ref<PhysicsMaterial> get_physics_material_override() const;
  158. void set_linear_velocity(const Vector3 &p_velocity);
  159. Vector3 get_linear_velocity() const;
  160. void set_axis_velocity(const Vector3 &p_axis);
  161. void set_angular_velocity(const Vector3 &p_velocity);
  162. Vector3 get_angular_velocity() const;
  163. Basis get_inverse_inertia_tensor();
  164. void set_gravity_scale(real_t p_gravity_scale);
  165. real_t get_gravity_scale() const;
  166. void set_linear_damp(real_t p_linear_damp);
  167. real_t get_linear_damp() const;
  168. void set_angular_damp(real_t p_angular_damp);
  169. real_t get_angular_damp() const;
  170. void set_use_custom_integrator(bool p_enable);
  171. bool is_using_custom_integrator();
  172. void set_sleeping(bool p_sleeping);
  173. bool is_sleeping() const;
  174. void set_can_sleep(bool p_active);
  175. bool is_able_to_sleep() const;
  176. void set_contact_monitor(bool p_enabled);
  177. bool is_contact_monitor_enabled() const;
  178. void set_max_contacts_reported(int p_amount);
  179. int get_max_contacts_reported() const;
  180. void set_use_continuous_collision_detection(bool p_enable);
  181. bool is_using_continuous_collision_detection() const;
  182. void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock);
  183. bool get_axis_lock(PhysicsServer::BodyAxis p_axis) const;
  184. Array get_colliding_bodies() const;
  185. void add_central_force(const Vector3 &p_force);
  186. void add_force(const Vector3 &p_force, const Vector3 &p_pos);
  187. void add_torque(const Vector3 &p_torque);
  188. void apply_central_impulse(const Vector3 &p_impulse);
  189. void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
  190. void apply_torque_impulse(const Vector3 &p_impulse);
  191. virtual String get_configuration_warning() const;
  192. RigidBody();
  193. ~RigidBody();
  194. private:
  195. void _reload_physics_characteristics();
  196. };
  197. VARIANT_ENUM_CAST(RigidBody::Mode);
  198. class KinematicCollision;
  199. class KinematicBody : public PhysicsBody {
  200. GDCLASS(KinematicBody, PhysicsBody);
  201. public:
  202. enum MovingPlatformApplyVelocityOnLeave {
  203. PLATFORM_VEL_ON_LEAVE_ALWAYS,
  204. PLATFORM_VEL_ON_LEAVE_UPWARD_ONLY,
  205. PLATFORM_VEL_ON_LEAVE_NEVER,
  206. };
  207. struct Collision {
  208. Vector3 collision;
  209. Vector3 normal;
  210. Vector3 collider_vel;
  211. ObjectID collider;
  212. RID collider_rid;
  213. int collider_shape;
  214. Variant collider_metadata;
  215. Vector3 remainder;
  216. Vector3 travel;
  217. int local_shape;
  218. real_t collision_safe_fraction;
  219. real_t get_angle(const Vector3 &p_up_direction) const {
  220. return Math::acos(normal.dot(p_up_direction));
  221. }
  222. };
  223. private:
  224. uint16_t locked_axis;
  225. float margin;
  226. Vector3 floor_normal;
  227. Vector3 floor_velocity;
  228. RID on_floor_body;
  229. bool on_floor;
  230. bool on_ceiling;
  231. bool on_wall;
  232. bool sync_to_physics = false;
  233. MovingPlatformApplyVelocityOnLeave moving_platform_apply_velocity_on_leave = PLATFORM_VEL_ON_LEAVE_ALWAYS;
  234. Vector<Collision> colliders;
  235. Vector<Ref<KinematicCollision>> slide_colliders;
  236. Ref<KinematicCollision> motion_cache;
  237. Ref<KinematicCollision> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false);
  238. Ref<KinematicCollision> _get_slide_collision(int p_bounce);
  239. Ref<KinematicCollision> _get_last_slide_collision();
  240. Transform last_valid_transform;
  241. void _direct_state_changed(Object *p_state);
  242. Vector3 _move_and_slide_internal(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_up_direction = Vector3(0, 0, 0), bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45), bool p_infinite_inertia = true);
  243. void _set_collision_direction(const Collision &p_collision, const Vector3 &p_up_direction, float p_floor_max_angle);
  244. void set_moving_platform_apply_velocity_on_leave(MovingPlatformApplyVelocityOnLeave p_on_leave_velocity);
  245. MovingPlatformApplyVelocityOnLeave get_moving_platform_apply_velocity_on_leave() const;
  246. protected:
  247. void _notification(int p_what);
  248. static void _bind_methods();
  249. public:
  250. bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes = true, bool p_test_only = false, bool p_cancel_sliding = true, const Set<RID> &p_exclude = Set<RID>());
  251. bool test_move(const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia);
  252. bool separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision);
  253. void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock);
  254. bool get_axis_lock(PhysicsServer::BodyAxis p_axis) const;
  255. void set_safe_margin(float p_margin);
  256. float get_safe_margin() const;
  257. Vector3 move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_up_direction = Vector3(0, 0, 0), bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45), bool p_infinite_inertia = true);
  258. Vector3 move_and_slide_with_snap(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_up_direction = Vector3(0, 0, 0), bool p_stop_on_slope = false, int p_max_slides = 4, float p_floor_max_angle = Math::deg2rad((float)45), bool p_infinite_inertia = true);
  259. bool is_on_floor() const;
  260. bool is_on_wall() const;
  261. bool is_on_ceiling() const;
  262. Vector3 get_floor_normal() const;
  263. real_t get_floor_angle(const Vector3 &p_up_direction = Vector3(0.0, 1.0, 0.0)) const;
  264. Vector3 get_floor_velocity() const;
  265. int get_slide_count() const;
  266. Collision get_slide_collision(int p_bounce) const;
  267. void set_sync_to_physics(bool p_enable);
  268. bool is_sync_to_physics_enabled() const;
  269. KinematicBody();
  270. ~KinematicBody();
  271. };
  272. VARIANT_ENUM_CAST(KinematicBody::MovingPlatformApplyVelocityOnLeave);
  273. class KinematicCollision : public Reference {
  274. GDCLASS(KinematicCollision, Reference);
  275. KinematicBody *owner;
  276. friend class KinematicBody;
  277. KinematicBody::Collision collision;
  278. protected:
  279. static void _bind_methods();
  280. public:
  281. Vector3 get_position() const;
  282. Vector3 get_normal() const;
  283. Vector3 get_travel() const;
  284. Vector3 get_remainder() const;
  285. real_t get_angle(const Vector3 &p_up_direction = Vector3(0.0, 1.0, 0.0)) const;
  286. Object *get_local_shape() const;
  287. Object *get_collider() const;
  288. ObjectID get_collider_id() const;
  289. RID get_collider_rid() const;
  290. Object *get_collider_shape() const;
  291. int get_collider_shape_index() const;
  292. Vector3 get_collider_velocity() const;
  293. Variant get_collider_metadata() const;
  294. KinematicCollision();
  295. };
  296. class PhysicalBone : public PhysicsBody {
  297. GDCLASS(PhysicalBone, PhysicsBody);
  298. public:
  299. enum JointType {
  300. JOINT_TYPE_NONE,
  301. JOINT_TYPE_PIN,
  302. JOINT_TYPE_CONE,
  303. JOINT_TYPE_HINGE,
  304. JOINT_TYPE_SLIDER,
  305. JOINT_TYPE_6DOF
  306. };
  307. struct JointData {
  308. virtual JointType get_joint_type() { return JOINT_TYPE_NONE; }
  309. /// "j" is used to set the parameter inside the PhysicsServer
  310. virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
  311. virtual bool _get(const StringName &p_name, Variant &r_ret) const;
  312. virtual void _get_property_list(List<PropertyInfo> *p_list) const;
  313. virtual ~JointData() {}
  314. };
  315. struct PinJointData : public JointData {
  316. virtual JointType get_joint_type() { return JOINT_TYPE_PIN; }
  317. virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
  318. virtual bool _get(const StringName &p_name, Variant &r_ret) const;
  319. virtual void _get_property_list(List<PropertyInfo> *p_list) const;
  320. real_t bias;
  321. real_t damping;
  322. real_t impulse_clamp;
  323. PinJointData() :
  324. bias(0.3),
  325. damping(1.),
  326. impulse_clamp(0) {}
  327. };
  328. struct ConeJointData : public JointData {
  329. virtual JointType get_joint_type() { return JOINT_TYPE_CONE; }
  330. virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
  331. virtual bool _get(const StringName &p_name, Variant &r_ret) const;
  332. virtual void _get_property_list(List<PropertyInfo> *p_list) const;
  333. real_t swing_span;
  334. real_t twist_span;
  335. real_t bias;
  336. real_t softness;
  337. real_t relaxation;
  338. ConeJointData() :
  339. swing_span(Math_PI * 0.25),
  340. twist_span(Math_PI),
  341. bias(0.3),
  342. softness(0.8),
  343. relaxation(1.) {}
  344. };
  345. struct HingeJointData : public JointData {
  346. virtual JointType get_joint_type() { return JOINT_TYPE_HINGE; }
  347. virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
  348. virtual bool _get(const StringName &p_name, Variant &r_ret) const;
  349. virtual void _get_property_list(List<PropertyInfo> *p_list) const;
  350. bool angular_limit_enabled;
  351. real_t angular_limit_upper;
  352. real_t angular_limit_lower;
  353. real_t angular_limit_bias;
  354. real_t angular_limit_softness;
  355. real_t angular_limit_relaxation;
  356. HingeJointData() :
  357. angular_limit_enabled(false),
  358. angular_limit_upper(Math_PI * 0.5),
  359. angular_limit_lower(-Math_PI * 0.5),
  360. angular_limit_bias(0.3),
  361. angular_limit_softness(0.9),
  362. angular_limit_relaxation(1.) {}
  363. };
  364. struct SliderJointData : public JointData {
  365. virtual JointType get_joint_type() { return JOINT_TYPE_SLIDER; }
  366. virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
  367. virtual bool _get(const StringName &p_name, Variant &r_ret) const;
  368. virtual void _get_property_list(List<PropertyInfo> *p_list) const;
  369. real_t linear_limit_upper;
  370. real_t linear_limit_lower;
  371. real_t linear_limit_softness;
  372. real_t linear_limit_restitution;
  373. real_t linear_limit_damping;
  374. real_t angular_limit_upper;
  375. real_t angular_limit_lower;
  376. real_t angular_limit_softness;
  377. real_t angular_limit_restitution;
  378. real_t angular_limit_damping;
  379. SliderJointData() :
  380. linear_limit_upper(1.),
  381. linear_limit_lower(-1.),
  382. linear_limit_softness(1.),
  383. linear_limit_restitution(0.7),
  384. linear_limit_damping(1.),
  385. angular_limit_upper(0),
  386. angular_limit_lower(0),
  387. angular_limit_softness(1.),
  388. angular_limit_restitution(0.7),
  389. angular_limit_damping(1.) {}
  390. };
  391. struct SixDOFJointData : public JointData {
  392. struct SixDOFAxisData {
  393. bool linear_limit_enabled;
  394. real_t linear_limit_upper;
  395. real_t linear_limit_lower;
  396. real_t linear_limit_softness;
  397. real_t linear_restitution;
  398. real_t linear_damping;
  399. bool linear_spring_enabled;
  400. real_t linear_spring_stiffness;
  401. real_t linear_spring_damping;
  402. real_t linear_equilibrium_point;
  403. bool angular_limit_enabled;
  404. real_t angular_limit_upper;
  405. real_t angular_limit_lower;
  406. real_t angular_limit_softness;
  407. real_t angular_restitution;
  408. real_t angular_damping;
  409. real_t erp;
  410. bool angular_spring_enabled;
  411. real_t angular_spring_stiffness;
  412. real_t angular_spring_damping;
  413. real_t angular_equilibrium_point;
  414. SixDOFAxisData() :
  415. linear_limit_enabled(true),
  416. linear_limit_upper(0),
  417. linear_limit_lower(0),
  418. linear_limit_softness(0.7),
  419. linear_restitution(0.5),
  420. linear_damping(1.),
  421. linear_spring_enabled(false),
  422. linear_spring_stiffness(0),
  423. linear_spring_damping(0),
  424. linear_equilibrium_point(0),
  425. angular_limit_enabled(true),
  426. angular_limit_upper(0),
  427. angular_limit_lower(0),
  428. angular_limit_softness(0.5),
  429. angular_restitution(0),
  430. angular_damping(1.),
  431. erp(0.5),
  432. angular_spring_enabled(false),
  433. angular_spring_stiffness(0),
  434. angular_spring_damping(0.),
  435. angular_equilibrium_point(0) {}
  436. };
  437. virtual JointType get_joint_type() { return JOINT_TYPE_6DOF; }
  438. virtual bool _set(const StringName &p_name, const Variant &p_value, RID j);
  439. virtual bool _get(const StringName &p_name, Variant &r_ret) const;
  440. virtual void _get_property_list(List<PropertyInfo> *p_list) const;
  441. SixDOFAxisData axis_data[3];
  442. SixDOFJointData() {}
  443. };
  444. private:
  445. #ifdef TOOLS_ENABLED
  446. // if false gizmo move body
  447. bool gizmo_move_joint;
  448. #endif
  449. JointData *joint_data;
  450. Transform joint_offset;
  451. RID joint;
  452. Skeleton *parent_skeleton;
  453. Transform body_offset;
  454. Transform body_offset_inverse;
  455. bool static_body;
  456. bool _internal_static_body;
  457. bool simulate_physics;
  458. bool _internal_simulate_physics;
  459. int bone_id;
  460. String bone_name;
  461. real_t bounce;
  462. real_t mass;
  463. real_t friction;
  464. real_t gravity_scale;
  465. protected:
  466. bool _set(const StringName &p_name, const Variant &p_value);
  467. bool _get(const StringName &p_name, Variant &r_ret) const;
  468. void _get_property_list(List<PropertyInfo> *p_list) const;
  469. void _notification(int p_what);
  470. void _direct_state_changed(Object *p_state);
  471. static void _bind_methods();
  472. private:
  473. static Skeleton *find_skeleton_parent(Node *p_parent);
  474. void _fix_joint_offset();
  475. void _reload_joint();
  476. public:
  477. void _on_bone_parent_changed();
  478. void _set_gizmo_move_joint(bool p_move_joint);
  479. public:
  480. #ifdef TOOLS_ENABLED
  481. virtual Transform get_global_gizmo_transform() const;
  482. virtual Transform get_local_gizmo_transform() const;
  483. #endif
  484. const JointData *get_joint_data() const;
  485. Skeleton *find_skeleton_parent();
  486. int get_bone_id() const { return bone_id; }
  487. void set_joint_type(JointType p_joint_type);
  488. JointType get_joint_type() const;
  489. void set_joint_offset(const Transform &p_offset);
  490. const Transform &get_joint_offset() const;
  491. void set_body_offset(const Transform &p_offset);
  492. const Transform &get_body_offset() const;
  493. void set_static_body(bool p_static);
  494. bool is_static_body();
  495. void set_simulate_physics(bool p_simulate);
  496. bool get_simulate_physics();
  497. bool is_simulating_physics();
  498. void set_bone_name(const String &p_name);
  499. const String &get_bone_name() const;
  500. void set_mass(real_t p_mass);
  501. real_t get_mass() const;
  502. void set_weight(real_t p_weight);
  503. real_t get_weight() const;
  504. void set_friction(real_t p_friction);
  505. real_t get_friction() const;
  506. void set_bounce(real_t p_bounce);
  507. real_t get_bounce() const;
  508. void set_gravity_scale(real_t p_gravity_scale);
  509. real_t get_gravity_scale() const;
  510. void apply_central_impulse(const Vector3 &p_impulse);
  511. void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
  512. PhysicalBone();
  513. ~PhysicalBone();
  514. private:
  515. void update_bone_id();
  516. void update_offset();
  517. void reset_to_rest_position();
  518. void _reset_physics_simulation_state();
  519. void _reset_staticness_state();
  520. void _start_physics_simulation();
  521. void _stop_physics_simulation();
  522. };
  523. VARIANT_ENUM_CAST(PhysicalBone::JointType);
  524. #endif // PHYSICS_BODY_H