summaryrefslogtreecommitdiff
path: root/scene/3d/physics_body_3d.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/physics_body_3d.h')
-rw-r--r--scene/3d/physics_body_3d.h138
1 files changed, 78 insertions, 60 deletions
diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h
index da008ab8cb..d5e474c5d5 100644
--- a/scene/3d/physics_body_3d.h
+++ b/scene/3d/physics_body_3d.h
@@ -37,6 +37,8 @@
#include "servers/physics_server_3d.h"
#include "skeleton_3d.h"
+class KinematicCollision3D;
+
class PhysicsBody3D : public CollisionObject3D {
GDCLASS(PhysicsBody3D, CollisionObject3D);
@@ -44,7 +46,19 @@ protected:
static void _bind_methods();
PhysicsBody3D(PhysicsServer3D::BodyMode p_mode);
+ Ref<KinematicCollision3D> motion_cache;
+
+ uint16_t locked_axis = 0;
+
+ Ref<KinematicCollision3D> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false, real_t p_margin = 0.001);
+
public:
+ bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false);
+ bool test_move(const Transform3D &p_from, const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, const Ref<KinematicCollision3D> &r_collision = Ref<KinematicCollision3D>(), real_t p_margin = 0.001);
+
+ void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock);
+ bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const;
+
virtual Vector3 get_linear_velocity() const;
virtual Vector3 get_angular_velocity() const;
virtual real_t get_inverse_mass() const;
@@ -53,7 +67,7 @@ public:
void add_collision_exception_with(Node *p_node); //must be physicsbody
void remove_collision_exception_with(Node *p_node);
- PhysicsBody3D();
+ virtual ~PhysicsBody3D();
};
class StaticBody3D : public PhysicsBody3D {
@@ -62,11 +76,19 @@ class StaticBody3D : public PhysicsBody3D {
Vector3 constant_linear_velocity;
Vector3 constant_angular_velocity;
+ Vector3 linear_velocity;
+ Vector3 angular_velocity;
+
Ref<PhysicsMaterial> physics_material_override;
+ bool kinematic_motion = false;
+
protected:
+ void _notification(int p_what);
static void _bind_methods();
+ void _direct_state_changed(Object *p_state);
+
public:
void set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override);
Ref<PhysicsMaterial> get_physics_material_override() const;
@@ -77,11 +99,18 @@ public:
Vector3 get_constant_linear_velocity() const;
Vector3 get_constant_angular_velocity() const;
+ virtual Vector3 get_linear_velocity() const override;
+ virtual Vector3 get_angular_velocity() const override;
+
StaticBody3D();
- ~StaticBody3D();
private:
void _reload_physics_characteristics();
+
+ void _update_kinematic_motion();
+
+ void set_kinematic_motion_enabled(bool p_enabled);
+ bool is_kinematic_motion_enabled() const;
};
class RigidBody3D : public PhysicsBody3D {
@@ -89,16 +118,16 @@ class RigidBody3D : public PhysicsBody3D {
public:
enum Mode {
- MODE_RIGID,
+ MODE_DYNAMIC,
MODE_STATIC,
- MODE_CHARACTER,
+ MODE_DYNAMIC_LOCKED,
MODE_KINEMATIC,
};
protected:
bool can_sleep = true;
PhysicsDirectBodyState3D *state = nullptr;
- Mode mode = MODE_RIGID;
+ Mode mode = MODE_DYNAMIC;
real_t mass = 1.0;
Ref<PhysicsMaterial> physics_material_override;
@@ -212,9 +241,6 @@ public:
void set_use_continuous_collision_detection(bool p_enable);
bool is_using_continuous_collision_detection() const;
- void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock);
- bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const;
-
Array get_colliding_bodies() const;
void add_central_force(const Vector3 &p_force);
@@ -238,30 +264,20 @@ VARIANT_ENUM_CAST(RigidBody3D::Mode);
class KinematicCollision3D;
-class KinematicBody3D : public PhysicsBody3D {
- GDCLASS(KinematicBody3D, PhysicsBody3D);
-
-public:
- struct Collision {
- Vector3 collision;
- Vector3 normal;
- Vector3 collider_vel;
- ObjectID collider;
- RID collider_rid;
- int collider_shape = 0;
- Variant collider_metadata;
- Vector3 remainder;
- Vector3 travel;
- int local_shape = 0;
- };
+class CharacterBody3D : public PhysicsBody3D {
+ GDCLASS(CharacterBody3D, PhysicsBody3D);
private:
- Vector3 linear_velocity;
- Vector3 angular_velocity;
+ real_t margin = 0.001;
- uint16_t locked_axis = 0;
+ bool stop_on_slope = false;
+ bool infinite_inertia = true;
+ int max_slides = 4;
+ real_t floor_max_angle = Math::deg2rad((real_t)45.0);
+ Vector3 snap;
+ Vector3 up_direction = Vector3(0.0, 1.0, 0.0);
- real_t margin;
+ Vector3 linear_velocity;
Vector3 floor_normal;
Vector3 floor_velocity;
@@ -269,38 +285,44 @@ private:
bool on_floor = false;
bool on_ceiling = false;
bool on_wall = false;
- Vector<Collision> colliders;
+ Vector<PhysicsServer3D::MotionResult> motion_results;
Vector<Ref<KinematicCollision3D>> slide_colliders;
- Ref<KinematicCollision3D> motion_cache;
-
- _FORCE_INLINE_ bool _ignores_mode(PhysicsServer3D::BodyMode) const;
- Ref<KinematicCollision3D> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false);
Ref<KinematicCollision3D> _get_slide_collision(int p_bounce);
-protected:
- void _notification(int p_what);
- static void _bind_methods();
+ bool separate_raycast_shapes(PhysicsServer3D::MotionResult &r_result);
- virtual void _direct_state_changed(Object *p_state);
+ void set_safe_margin(real_t p_margin);
+ real_t get_safe_margin() const;
-public:
- virtual Vector3 get_linear_velocity() const override;
- virtual Vector3 get_angular_velocity() const override;
+ bool is_stop_on_slope_enabled() const;
+ void set_stop_on_slope_enabled(bool p_enabled);
- 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 test_move(const Transform3D &p_from, const Vector3 &p_motion, bool p_infinite_inertia);
+ bool is_infinite_inertia_enabled() const;
+ void set_infinite_inertia_enabled(bool p_enabled);
- bool separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision);
+ int get_max_slides() const;
+ void set_max_slides(int p_max_slides);
- void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock);
- bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const;
+ real_t get_floor_max_angle() const;
+ void set_floor_max_angle(real_t p_floor_max_angle);
- void set_safe_margin(real_t p_margin);
- real_t get_safe_margin() const;
+ const Vector3 &get_snap() const;
+ void set_snap(const Vector3 &p_snap);
+
+ const Vector3 &get_up_direction() const;
+ void set_up_direction(const Vector3 &p_up_direction);
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ void move_and_slide();
+
+ virtual Vector3 get_linear_velocity() const override;
+ void set_linear_velocity(const Vector3 &p_velocity);
- 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, real_t p_floor_max_angle = Math::deg2rad((real_t)45.0), bool p_infinite_inertia = true);
- 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, real_t p_floor_max_angle = Math::deg2rad((real_t)45.0), bool p_infinite_inertia = true);
bool is_on_floor() const;
bool is_on_wall() const;
bool is_on_ceiling() const;
@@ -308,18 +330,19 @@ public:
Vector3 get_floor_velocity() const;
int get_slide_count() const;
- Collision get_slide_collision(int p_bounce) const;
+ PhysicsServer3D::MotionResult get_slide_collision(int p_bounce) const;
- KinematicBody3D();
- ~KinematicBody3D();
+ CharacterBody3D();
+ ~CharacterBody3D();
};
class KinematicCollision3D : public Reference {
GDCLASS(KinematicCollision3D, Reference);
- KinematicBody3D *owner;
- friend class KinematicBody3D;
- KinematicBody3D::Collision collision;
+ PhysicsBody3D *owner = nullptr;
+ friend class PhysicsBody3D;
+ friend class CharacterBody3D;
+ PhysicsServer3D::MotionResult result;
protected:
static void _bind_methods();
@@ -336,8 +359,6 @@ public:
int get_collider_shape_index() const;
Vector3 get_collider_velocity() const;
Variant get_collider_metadata() const;
-
- KinematicCollision3D();
};
class PhysicalBone3D : public PhysicsBody3D {
@@ -560,9 +581,6 @@ public:
void set_can_sleep(bool p_active);
bool is_able_to_sleep() const;
- void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock);
- bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const;
-
void apply_central_impulse(const Vector3 &p_impulse);
void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3());