From daf7dcac7a9e0b4c26ba62ba9a700813d5abec9a Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Tue, 14 Apr 2020 19:59:53 +0200 Subject: [PATCH] Improved RigidDynamicBody linear/angular damping override Damping values are now non-negative. Add new properties linear_damp_mode and angular_damp_mode to set the way RigidDynamicBody and PhysicalBone (2D & 3D) use damping values. It can now be Combine (default) to add to the default/areas, or Replace to override the value completely (current behavior). --- doc/classes/PhysicalBone3D.xml | 22 ++++- doc/classes/PhysicsServer2D.xml | 18 +++- doc/classes/PhysicsServer3D.xml | 18 +++- doc/classes/RigidDynamicBody2D.xml | 20 +++- doc/classes/RigidDynamicBody3D.xml | 20 +++- scene/2d/physics_body_2d.cpp | 29 ++++++ scene/2d/physics_body_2d.h | 20 +++- scene/3d/physics_body_3d.cpp | 76 +++++++++++++-- scene/3d/physics_body_3d.h | 40 +++++++- scene/resources/world_3d.cpp | 4 +- servers/physics_2d/godot_body_2d.cpp | 92 ++++++++++--------- servers/physics_2d/godot_body_2d.h | 18 ++-- .../physics_2d/godot_body_direct_state_2d.cpp | 4 +- servers/physics_3d/godot_body_3d.cpp | 82 ++++++++++------- servers/physics_3d/godot_body_3d.h | 15 +-- .../physics_3d/godot_body_direct_state_3d.cpp | 4 +- servers/physics_server_2d.cpp | 5 + servers/physics_server_2d.h | 9 +- servers/physics_server_3d.cpp | 5 + servers/physics_server_3d.h | 8 ++ 20 files changed, 382 insertions(+), 127 deletions(-) diff --git a/doc/classes/PhysicalBone3D.xml b/doc/classes/PhysicalBone3D.xml index 710e96239b..a9963d59e8 100644 --- a/doc/classes/PhysicalBone3D.xml +++ b/doc/classes/PhysicalBone3D.xml @@ -37,8 +37,12 @@ - - Damps the body's rotation if greater than [code]0[/code]. + + Damps the body's rotation. By default, the body will use the [b]Default Angular Damp[/b] in [b]Project > Project Settings > Physics > 3d[/b] or any value override set by an [Area3D] the body is in. Depending on [member angular_damp_mode], you can set [member angular_damp] to be added to or to replace the body's damping value. + See [member ProjectSettings.physics/3d/default_angular_damp] for more details about damping. + + + Defines how [member angular_damp] is applied. See [enum DampMode] for possible values. Sets the body's transform. @@ -64,14 +68,24 @@ Sets the joint type. See [enum JointType] for possible values. - - Damps the body's movement if greater than [code]0[/code]. + + Damps the body's movement. By default, the body will use the [b]Default Linear Damp[/b] in [b]Project > Project Settings > Physics > 3d[/b] or any value override set by an [Area3D] the body is in. Depending on [member linear_damp_mode], you can set [member linear_damp] to be added to or to replace the body's damping value. + See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping. + + + Defines how [member linear_damp] is applied. See [enum DampMode] for possible values. The body's mass. + + In this mode, the body's damping value is added to any value set in areas or the default value. + + + In this mode, the body's damping value replaces any value set in areas or the default value. + diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml index d55feff829..24a20b5613 100644 --- a/doc/classes/PhysicsServer2D.xml +++ b/doc/classes/PhysicsServer2D.xml @@ -926,15 +926,27 @@ Constant to set/get a body's gravity multiplier. - + + Constant to set/get a body's linear dampening mode. See [enum BodyDampMode] for possible values. + + + Constant to set/get a body's angular dampening mode. See [enum BodyDampMode] for possible values. + + Constant to set/get a body's linear dampening factor. - + Constant to set/get a body's angular dampening factor. - + Represents the size of the [enum BodyParameter] enum. + + The body's damping value is added to any value set in areas or the default value. + + + The body's damping value replaces any value set in areas or the default value. + Constant to set/get the current transform matrix of the body. diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml index 0e32d1defa..034bd55519 100644 --- a/doc/classes/PhysicsServer3D.xml +++ b/doc/classes/PhysicsServer3D.xml @@ -1294,15 +1294,27 @@ Constant to set/get a body's gravity multiplier. - + + Constant to set/get a body's linear dampening mode. See [enum BodyDampMode] for possible values. + + + Constant to set/get a body's angular dampening mode. See [enum BodyDampMode] for possible values. + + Constant to set/get a body's linear dampening factor. - + Constant to set/get a body's angular dampening factor. - + Represents the size of the [enum BodyParameter] enum. + + The body's damping value is added to any value set in areas or the default value. + + + The body's damping value replaces any value set in areas or the default value. + Constant to set/get the current transform matrix of the body. diff --git a/doc/classes/RigidDynamicBody2D.xml b/doc/classes/RigidDynamicBody2D.xml index f503884192..b8680b99b3 100644 --- a/doc/classes/RigidDynamicBody2D.xml +++ b/doc/classes/RigidDynamicBody2D.xml @@ -82,10 +82,13 @@ - - Damps the body's [member angular_velocity]. If [code]-1[/code], the body will use the [b]Default Angular Damp[/b] defined in [b]Project > Project Settings > Physics > 2d[/b]. + + Damps the body's rotation. By default, the body will use the [b]Default Angular Damp[/b] in [b]Project > Project Settings > Physics > 2d[/b] or any value override set by an [Area2D] the body is in. Depending on [member angular_damp_mode], you can set [member angular_damp] to be added to or to replace the body's damping value. See [member ProjectSettings.physics/2d/default_angular_damp] for more details about damping. + + Defines how [member angular_damp] is applied. See [enum DampMode] for possible values. + The body's rotational velocity. @@ -135,10 +138,13 @@ The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value. If set to [code]0[/code], inertia is automatically computed (default value). - - Damps the body's [member linear_velocity]. If [code]-1[/code], the body will use the [b]Default Linear Damp[/b] in [b]Project > Project Settings > Physics > 2d[/b]. + + Damps the body's movement. By default, the body will use the [b]Default Linear Damp[/b] in [b]Project > Project Settings > Physics > 2d[/b] or any value override set by an [Area2D] the body is in. Depending on [member linear_damp_mode], you can set [member linear_damp] to be added to or to replace the body's damping value. See [member ProjectSettings.physics/2d/default_linear_damp] for more details about damping. + + Defines how [member linear_damp] is applied. See [enum DampMode] for possible values. + The body's linear velocity. @@ -217,6 +223,12 @@ In this mode, the body's center of mass is set through [member center_of_mass]. Defaults to the body's origin position. + + In this mode, the body's damping value is added to any value set in areas or the default value. + + + In this mode, the body's damping value replaces any value set in areas or the default value. + Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects. diff --git a/doc/classes/RigidDynamicBody3D.xml b/doc/classes/RigidDynamicBody3D.xml index 6c8d190704..ba9acdf4bf 100644 --- a/doc/classes/RigidDynamicBody3D.xml +++ b/doc/classes/RigidDynamicBody3D.xml @@ -91,10 +91,13 @@ - - Damps RigidDynamicBody3D's rotational forces. + + Damps the body's rotation. By default, the body will use the [b]Default Angular Damp[/b] in [b]Project > Project Settings > Physics > 3d[/b] or any value override set by an [Area3D] the body is in. Depending on [member angular_damp_mode], you can set [member angular_damp] to be added to or to replace the body's damping value. See [member ProjectSettings.physics/3d/default_angular_damp] for more details about damping. + + Defines how [member angular_damp] is applied. See [enum DampMode] for possible values. + RigidDynamicBody3D's rotational velocity. @@ -138,10 +141,13 @@ The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body on each axis. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value. If set to [code]Vector3.ZERO[/code], inertia is automatically computed (default value). - - The body's linear damp. Cannot be less than -1.0. If this value is different from -1.0, any linear damp derived from the world or areas will be overridden. + + Damps the body's movement. By default, the body will use the [b]Default Linear Damp[/b] in [b]Project > Project Settings > Physics > 3d[/b] or any value override set by an [Area3D] the body is in. Depending on [member linear_damp_mode], you can set [member linear_damp] to be added to or to replace the body's damping value. See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping. + + Defines how [member linear_damp] is applied. See [enum DampMode] for possible values. + The body's linear velocity. Can be used sporadically, but [b]don't set this every frame[/b], because physics may run in another thread and runs at a different granularity. Use [method _integrate_forces] as your process loop for precise control of the body state. @@ -222,5 +228,11 @@ In this mode, the body's center of mass is set through [member center_of_mass]. Defaults to the body's origin position. + + In this mode, the body's damping value is added to any value set in areas or the default value. + + + In this mode, the body's damping value replaces any value set in areas or the default value. + diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 41288d646f..221576e1af 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -684,6 +684,24 @@ real_t RigidDynamicBody2D::get_gravity_scale() const { return gravity_scale; } +void RigidDynamicBody2D::set_linear_damp_mode(DampMode p_mode) { + linear_damp_mode = p_mode; + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_LINEAR_DAMP_MODE, linear_damp_mode); +} + +RigidDynamicBody2D::DampMode RigidDynamicBody2D::get_linear_damp_mode() const { + return linear_damp_mode; +} + +void RigidDynamicBody2D::set_angular_damp_mode(DampMode p_mode) { + angular_damp_mode = p_mode; + PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP_MODE, angular_damp_mode); +} + +RigidDynamicBody2D::DampMode RigidDynamicBody2D::get_angular_damp_mode() const { + return angular_damp_mode; +} + void RigidDynamicBody2D::set_linear_damp(real_t p_linear_damp) { ERR_FAIL_COND(p_linear_damp < -1); linear_damp = p_linear_damp; @@ -916,6 +934,12 @@ void RigidDynamicBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidDynamicBody2D::set_gravity_scale); ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidDynamicBody2D::get_gravity_scale); + ClassDB::bind_method(D_METHOD("set_linear_damp_mode", "linear_damp_mode"), &RigidDynamicBody2D::set_linear_damp_mode); + ClassDB::bind_method(D_METHOD("get_linear_damp_mode"), &RigidDynamicBody2D::get_linear_damp_mode); + + ClassDB::bind_method(D_METHOD("set_angular_damp_mode", "angular_damp_mode"), &RigidDynamicBody2D::set_angular_damp_mode); + ClassDB::bind_method(D_METHOD("get_angular_damp_mode"), &RigidDynamicBody2D::get_angular_damp_mode); + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidDynamicBody2D::set_linear_damp); ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidDynamicBody2D::get_linear_damp); @@ -992,9 +1016,11 @@ void RigidDynamicBody2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "freeze_mode", PROPERTY_HINT_ENUM, "Static,Kinematic"), "set_freeze_mode", "get_freeze_mode"); ADD_GROUP("Linear", "linear_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "linear_velocity"), "set_linear_velocity", "get_linear_velocity"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "linear_damp_mode", PROPERTY_HINT_ENUM, "Combine,Replace"), "set_linear_damp_mode", "get_linear_damp_mode"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); ADD_GROUP("Angular", "angular_"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_velocity"), "set_angular_velocity", "get_angular_velocity"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "angular_damp_mode", PROPERTY_HINT_ENUM, "Combine,Replace"), "set_angular_damp_mode", "get_angular_damp_mode"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); ADD_GROUP("Applied Forces", "applied_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "applied_force"), "set_applied_force", "get_applied_force"); @@ -1012,6 +1038,9 @@ void RigidDynamicBody2D::_bind_methods() { BIND_ENUM_CONSTANT(CENTER_OF_MASS_MODE_AUTO); BIND_ENUM_CONSTANT(CENTER_OF_MASS_MODE_CUSTOM); + BIND_ENUM_CONSTANT(DAMP_MODE_COMBINE); + BIND_ENUM_CONSTANT(DAMP_MODE_REPLACE); + BIND_ENUM_CONSTANT(CCD_MODE_DISABLED); BIND_ENUM_CONSTANT(CCD_MODE_CAST_RAY); BIND_ENUM_CONSTANT(CCD_MODE_CAST_SHAPE); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index d1f52b33f2..74bdf76359 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -127,6 +127,11 @@ public: CENTER_OF_MASS_MODE_CUSTOM, }; + enum DampMode { + DAMP_MODE_COMBINE, + DAMP_MODE_REPLACE, + }; + enum CCDMode { CCD_MODE_DISABLED, CCD_MODE_CAST_RAY, @@ -146,8 +151,12 @@ private: Ref physics_material_override; real_t gravity_scale = 1.0; - real_t linear_damp = -1.0; - real_t angular_damp = -1.0; + + DampMode linear_damp_mode = DAMP_MODE_COMBINE; + DampMode angular_damp_mode = DAMP_MODE_COMBINE; + + real_t linear_damp = 0.0; + real_t angular_damp = 0.0; Vector2 linear_velocity; real_t angular_velocity = 0.0; @@ -241,6 +250,12 @@ public: void set_gravity_scale(real_t p_gravity_scale); real_t get_gravity_scale() const; + void set_linear_damp_mode(DampMode p_mode); + DampMode get_linear_damp_mode() const; + + void set_angular_damp_mode(DampMode p_mode); + DampMode get_angular_damp_mode() const; + void set_linear_damp(real_t p_linear_damp); real_t get_linear_damp() const; @@ -300,6 +315,7 @@ private: VARIANT_ENUM_CAST(RigidDynamicBody2D::FreezeMode); VARIANT_ENUM_CAST(RigidDynamicBody2D::CenterOfMassMode); +VARIANT_ENUM_CAST(RigidDynamicBody2D::DampMode); VARIANT_ENUM_CAST(RigidDynamicBody2D::CCDMode); class CharacterBody2D : public PhysicsBody2D { diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 8cb348d6e3..7ee5e74f93 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -758,8 +758,26 @@ real_t RigidDynamicBody3D::get_gravity_scale() const { return gravity_scale; } +void RigidDynamicBody3D::set_linear_damp_mode(DampMode p_mode) { + linear_damp_mode = p_mode; + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP_MODE, linear_damp_mode); +} + +RigidDynamicBody3D::DampMode RigidDynamicBody3D::get_linear_damp_mode() const { + return linear_damp_mode; +} + +void RigidDynamicBody3D::set_angular_damp_mode(DampMode p_mode) { + angular_damp_mode = p_mode; + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP_MODE, angular_damp_mode); +} + +RigidDynamicBody3D::DampMode RigidDynamicBody3D::get_angular_damp_mode() const { + return angular_damp_mode; +} + void RigidDynamicBody3D::set_linear_damp(real_t p_linear_damp) { - ERR_FAIL_COND(p_linear_damp < -1); + ERR_FAIL_COND(p_linear_damp < 0.0); linear_damp = p_linear_damp; PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP, linear_damp); } @@ -769,7 +787,7 @@ real_t RigidDynamicBody3D::get_linear_damp() const { } void RigidDynamicBody3D::set_angular_damp(real_t p_angular_damp) { - ERR_FAIL_COND(p_angular_damp < -1); + ERR_FAIL_COND(p_angular_damp < 0.0); angular_damp = p_angular_damp; PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, angular_damp); } @@ -970,6 +988,12 @@ void RigidDynamicBody3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidDynamicBody3D::set_gravity_scale); ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidDynamicBody3D::get_gravity_scale); + ClassDB::bind_method(D_METHOD("set_linear_damp_mode", "linear_damp_mode"), &RigidDynamicBody3D::set_linear_damp_mode); + ClassDB::bind_method(D_METHOD("get_linear_damp_mode"), &RigidDynamicBody3D::get_linear_damp_mode); + + ClassDB::bind_method(D_METHOD("set_angular_damp_mode", "angular_damp_mode"), &RigidDynamicBody3D::set_angular_damp_mode); + ClassDB::bind_method(D_METHOD("get_angular_damp_mode"), &RigidDynamicBody3D::get_angular_damp_mode); + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidDynamicBody3D::set_linear_damp); ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidDynamicBody3D::get_linear_damp); @@ -1035,10 +1059,12 @@ void RigidDynamicBody3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "freeze_mode", PROPERTY_HINT_ENUM, "Static,Kinematic"), "set_freeze_mode", "get_freeze_mode"); ADD_GROUP("Linear", "linear_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "linear_damp_mode", PROPERTY_HINT_ENUM, "Combine,Replace"), "set_linear_damp_mode", "get_linear_damp_mode"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); ADD_GROUP("Angular", "angular_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "angular_velocity"), "set_angular_velocity", "get_angular_velocity"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "angular_damp_mode", PROPERTY_HINT_ENUM, "Combine,Replace"), "set_angular_damp_mode", "get_angular_damp_mode"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::RID, "body_rid"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape_index"), PropertyInfo(Variant::INT, "local_shape_index"))); ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::RID, "body_rid"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape_index"), PropertyInfo(Variant::INT, "local_shape_index"))); @@ -1051,6 +1077,9 @@ void RigidDynamicBody3D::_bind_methods() { BIND_ENUM_CONSTANT(CENTER_OF_MASS_MODE_AUTO); BIND_ENUM_CONSTANT(CENTER_OF_MASS_MODE_CUSTOM); + + BIND_ENUM_CONSTANT(DAMP_MODE_COMBINE); + BIND_ENUM_CONSTANT(DAMP_MODE_REPLACE); } void RigidDynamicBody3D::_validate_property(PropertyInfo &property) const { @@ -2823,6 +2852,12 @@ void PhysicalBone3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &PhysicalBone3D::set_gravity_scale); ClassDB::bind_method(D_METHOD("get_gravity_scale"), &PhysicalBone3D::get_gravity_scale); + ClassDB::bind_method(D_METHOD("set_linear_damp_mode", "linear_damp_mode"), &PhysicalBone3D::set_linear_damp_mode); + ClassDB::bind_method(D_METHOD("get_linear_damp_mode"), &PhysicalBone3D::get_linear_damp_mode); + + ClassDB::bind_method(D_METHOD("set_angular_damp_mode", "angular_damp_mode"), &PhysicalBone3D::set_angular_damp_mode); + ClassDB::bind_method(D_METHOD("get_angular_damp_mode"), &PhysicalBone3D::get_angular_damp_mode); + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &PhysicalBone3D::set_linear_damp); ClassDB::bind_method(D_METHOD("get_linear_damp"), &PhysicalBone3D::get_linear_damp); @@ -2843,10 +2878,15 @@ void PhysicalBone3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_friction", "get_friction"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_bounce", "get_bounce"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_scale", PROPERTY_HINT_RANGE, "-10,10,0.01"), "set_gravity_scale", "get_gravity_scale"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "linear_damp_mode", PROPERTY_HINT_ENUM, "Combine,Replace"), "set_linear_damp_mode", "get_linear_damp_mode"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "angular_damp_mode", PROPERTY_HINT_ENUM, "Combine,Replace"), "set_angular_damp_mode", "get_angular_damp_mode"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "can_sleep"), "set_can_sleep", "is_able_to_sleep"); + BIND_ENUM_CONSTANT(DAMP_MODE_COMBINE); + BIND_ENUM_CONSTANT(DAMP_MODE_REPLACE); + BIND_ENUM_CONSTANT(JOINT_TYPE_NONE); BIND_ENUM_CONSTANT(JOINT_TYPE_PIN); BIND_ENUM_CONSTANT(JOINT_TYPE_CONE); @@ -3144,8 +3184,27 @@ real_t PhysicalBone3D::get_gravity_scale() const { return gravity_scale; } +void PhysicalBone3D::set_linear_damp_mode(DampMode p_mode) { + linear_damp_mode = p_mode; + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP_MODE, linear_damp_mode); +} + +PhysicalBone3D::DampMode PhysicalBone3D::get_linear_damp_mode() const { + return linear_damp_mode; +} + +void PhysicalBone3D::set_angular_damp_mode(DampMode p_mode) { + angular_damp_mode = p_mode; + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP_MODE, angular_damp_mode); +} + +PhysicalBone3D::DampMode PhysicalBone3D::get_angular_damp_mode() const { + return angular_damp_mode; +} + void PhysicalBone3D::set_linear_damp(real_t p_linear_damp) { - ERR_FAIL_COND(p_linear_damp < -1); + ERR_FAIL_COND(p_linear_damp < 0); + linear_damp = p_linear_damp; PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP, linear_damp); } @@ -3155,7 +3214,8 @@ real_t PhysicalBone3D::get_linear_damp() const { } void PhysicalBone3D::set_angular_damp(real_t p_angular_damp) { - ERR_FAIL_COND(p_angular_damp < -1); + ERR_FAIL_COND(p_angular_damp < 0); + angular_damp = p_angular_damp; PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, angular_damp); } diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h index 5677df730c..2ea796d335 100644 --- a/scene/3d/physics_body_3d.h +++ b/scene/3d/physics_body_3d.h @@ -143,6 +143,11 @@ public: CENTER_OF_MASS_MODE_CUSTOM, }; + enum DampMode { + DAMP_MODE_COMBINE, + DAMP_MODE_REPLACE, + }; + private: bool can_sleep = true; bool lock_rotation = false; @@ -160,8 +165,12 @@ private: Vector3 angular_velocity; Basis inverse_inertia_tensor; real_t gravity_scale = 1.0; - real_t linear_damp = -1.0; - real_t angular_damp = -1.0; + + DampMode linear_damp_mode = DAMP_MODE_COMBINE; + DampMode angular_damp_mode = DAMP_MODE_COMBINE; + + real_t linear_damp = 0.0; + real_t angular_damp = 0.0; bool sleeping = false; bool ccd = false; @@ -265,6 +274,12 @@ public: void set_gravity_scale(real_t p_gravity_scale); real_t get_gravity_scale() const; + void set_linear_damp_mode(DampMode p_mode); + DampMode get_linear_damp_mode() const; + + void set_angular_damp_mode(DampMode p_mode); + DampMode get_angular_damp_mode() const; + void set_linear_damp(real_t p_linear_damp); real_t get_linear_damp() const; @@ -310,6 +325,7 @@ private: VARIANT_ENUM_CAST(RigidDynamicBody3D::FreezeMode); VARIANT_ENUM_CAST(RigidDynamicBody3D::CenterOfMassMode); +VARIANT_ENUM_CAST(RigidDynamicBody3D::DampMode); class KinematicCollision3D; @@ -494,6 +510,11 @@ class PhysicalBone3D : public PhysicsBody3D { GDCLASS(PhysicalBone3D, PhysicsBody3D); public: + enum DampMode { + DAMP_MODE_COMBINE, + DAMP_MODE_REPLACE, + }; + enum JointType { JOINT_TYPE_NONE, JOINT_TYPE_PIN, @@ -632,10 +653,14 @@ private: real_t mass = 1.0; real_t friction = 1.0; real_t gravity_scale = 1.0; - real_t linear_damp = -1.0; - real_t angular_damp = -1.0; bool can_sleep = true; + DampMode linear_damp_mode = DAMP_MODE_COMBINE; + DampMode angular_damp_mode = DAMP_MODE_COMBINE; + + real_t linear_damp = 0.0; + real_t angular_damp = 0.0; + protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; @@ -698,6 +723,12 @@ public: void set_gravity_scale(real_t p_gravity_scale); real_t get_gravity_scale() const; + void set_linear_damp_mode(DampMode p_mode); + DampMode get_linear_damp_mode() const; + + void set_angular_damp_mode(DampMode p_mode); + DampMode get_angular_damp_mode() const; + void set_linear_damp(real_t p_linear_damp); real_t get_linear_damp() const; @@ -725,5 +756,6 @@ private: }; VARIANT_ENUM_CAST(PhysicalBone3D::JointType); +VARIANT_ENUM_CAST(PhysicalBone3D::DampMode); #endif // PHYSICS_BODY__H diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp index 42047f104f..0e1b343eac 100644 --- a/scene/resources/world_3d.cpp +++ b/scene/resources/world_3d.cpp @@ -144,9 +144,9 @@ World3D::World3D() { PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_GRAVITY, GLOBAL_DEF("physics/3d/default_gravity", 9.8)); PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_DEF("physics/3d/default_gravity_vector", Vector3(0, -1, 0))); PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, GLOBAL_DEF("physics/3d/default_linear_damp", 0.1)); - ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_linear_damp", PropertyInfo(Variant::FLOAT, "physics/3d/default_linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); + ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_linear_damp", PropertyInfo(Variant::FLOAT, "physics/3d/default_linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater")); PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/3d/default_angular_damp", 0.1)); - ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_angular_damp", PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); + ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_angular_damp", PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater")); navigation_map = NavigationServer3D::get_singleton()->map_create(); NavigationServer3D::get_singleton()->map_set_active(navigation_map, true); diff --git a/servers/physics_2d/godot_body_2d.cpp b/servers/physics_2d/godot_body_2d.cpp index 56f191c203..109914d585 100644 --- a/servers/physics_2d/godot_body_2d.cpp +++ b/servers/physics_2d/godot_body_2d.cpp @@ -187,6 +187,14 @@ void GodotBody2D::set_param(PhysicsServer2D::BodyParameter p_param, const Varian case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: { gravity_scale = p_value; } break; + case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP_MODE: { + int mode_value = p_value; + linear_damp_mode = (PhysicsServer2D::BodyDampMode)mode_value; + } break; + case PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP_MODE: { + int mode_value = p_value; + angular_damp_mode = (PhysicsServer2D::BodyDampMode)mode_value; + } break; case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP: { linear_damp = p_value; } break; @@ -218,6 +226,12 @@ Variant GodotBody2D::get_param(PhysicsServer2D::BodyParameter p_param) const { case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: { return gravity_scale; } + case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP_MODE: { + return linear_damp_mode; + } + case PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP_MODE: { + return angular_damp_mode; + } case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP: { return linear_damp; } @@ -401,8 +415,8 @@ void GodotBody2D::_compute_area_gravity_and_damping(const GodotArea2D *p_area) { p_area->compute_gravity(get_transform().get_origin(), area_gravity); gravity += area_gravity; - area_linear_damp += p_area->get_linear_damp(); - area_angular_damp += p_area->get_angular_damp(); + total_linear_damp += p_area->get_linear_damp(); + total_angular_damp += p_area->get_angular_damp(); } void GodotBody2D::_update_transform_dependent() { @@ -414,19 +428,17 @@ void GodotBody2D::integrate_forces(real_t p_step) { return; } - GodotArea2D *def_area = get_space()->get_default_area(); - // GodotArea2D *damp_area = def_area; - ERR_FAIL_COND(!def_area); - int ac = areas.size(); bool stopped = false; gravity = Vector2(0, 0); - area_angular_damp = 0; - area_linear_damp = 0; + + total_linear_damp = 0.0; + total_angular_damp = 0.0; + + // Combine gravity and damping from overlapping areas in priority order. if (ac) { areas.sort(); const AreaCMP *aa = &areas[0]; - // damp_area = aa[ac-1].area; for (int i = ac - 1; i >= 0 && !stopped; i--) { PhysicsServer2D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode(); switch (mode) { @@ -438,8 +450,8 @@ void GodotBody2D::integrate_forces(real_t p_step) { case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE: case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: { gravity = Vector2(0, 0); - area_angular_damp = 0; - area_linear_damp = 0; + total_linear_damp = 0.0; + total_angular_damp = 0.0; _compute_area_gravity_and_damping(aa[i].area); stopped = mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE; } break; @@ -448,28 +460,37 @@ void GodotBody2D::integrate_forces(real_t p_step) { } } } + + // Override linear damping with body's value. if (!stopped) { + GodotArea2D *def_area = get_space()->get_default_area(); + ERR_FAIL_COND(!def_area); + _compute_area_gravity_and_damping(def_area); } + + // Override linear damping with body's value. + switch (linear_damp_mode) { + case PhysicsServer2D::BODY_DAMP_MODE_COMBINE: { + total_linear_damp += linear_damp; + } break; + case PhysicsServer2D::BODY_DAMP_MODE_REPLACE: { + total_linear_damp = linear_damp; + } break; + } + + // Override angular damping with body's value. + switch (angular_damp_mode) { + case PhysicsServer2D::BODY_DAMP_MODE_COMBINE: { + total_angular_damp += angular_damp; + } break; + case PhysicsServer2D::BODY_DAMP_MODE_REPLACE: { + total_angular_damp = angular_damp; + } break; + } + gravity *= gravity_scale; - // If less than 0, override dampenings with that of the Body2D - if (angular_damp >= 0) { - area_angular_damp = angular_damp; - } - /* - else - area_angular_damp=damp_area->get_angular_damp(); - */ - - if (linear_damp >= 0) { - area_linear_damp = linear_damp; - } - /* - else - area_linear_damp=damp_area->get_linear_damp(); - */ - Vector2 motion; bool do_motion = false; @@ -483,13 +504,6 @@ void GodotBody2D::integrate_forces(real_t p_step) { do_motion = true; - /* - for(int i=0;iarea_angular_damp; + return body->total_angular_damp; } real_t GodotPhysicsDirectBodyState2D::get_total_linear_damp() const { - return body->area_linear_damp; + return body->total_linear_damp; } Vector2 GodotPhysicsDirectBodyState2D::get_center_of_mass() const { diff --git a/servers/physics_3d/godot_body_3d.cpp b/servers/physics_3d/godot_body_3d.cpp index 02929eeaed..768c9e6572 100644 --- a/servers/physics_3d/godot_body_3d.cpp +++ b/servers/physics_3d/godot_body_3d.cpp @@ -229,6 +229,14 @@ void GodotBody3D::set_param(PhysicsServer3D::BodyParameter p_param, const Varian case PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE: { gravity_scale = p_value; } break; + case PhysicsServer3D::BODY_PARAM_LINEAR_DAMP_MODE: { + int mode_value = p_value; + linear_damp_mode = (PhysicsServer3D::BodyDampMode)mode_value; + } break; + case PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP_MODE: { + int mode_value = p_value; + angular_damp_mode = (PhysicsServer3D::BodyDampMode)mode_value; + } break; case PhysicsServer3D::BODY_PARAM_LINEAR_DAMP: { linear_damp = p_value; } break; @@ -264,6 +272,12 @@ Variant GodotBody3D::get_param(PhysicsServer3D::BodyParameter p_param) const { case PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE: { return gravity_scale; } break; + case PhysicsServer3D::BODY_PARAM_LINEAR_DAMP_MODE: { + return linear_damp_mode; + } + case PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP_MODE: { + return angular_damp_mode; + } case PhysicsServer3D::BODY_PARAM_LINEAR_DAMP: { return linear_damp; } break; @@ -448,8 +462,8 @@ void GodotBody3D::_compute_area_gravity_and_damping(const GodotArea3D *p_area) { p_area->compute_gravity(get_transform().get_origin(), area_gravity); gravity += area_gravity; - area_linear_damp += p_area->get_linear_damp(); - area_angular_damp += p_area->get_angular_damp(); + total_linear_damp += p_area->get_linear_damp(); + total_angular_damp += p_area->get_angular_damp(); } void GodotBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock) { @@ -469,19 +483,17 @@ void GodotBody3D::integrate_forces(real_t p_step) { return; } - GodotArea3D *def_area = get_space()->get_default_area(); - - ERR_FAIL_COND(!def_area); - int ac = areas.size(); bool stopped = false; gravity = Vector3(0, 0, 0); - area_linear_damp = 0; - area_angular_damp = 0; + + total_linear_damp = 0.0; + total_angular_damp = 0.0; + + // Combine gravity and damping from overlapping areas in priority order. if (ac) { areas.sort(); const AreaCMP *aa = &areas[0]; - // damp_area = aa[ac-1].area; for (int i = ac - 1; i >= 0 && !stopped; i--) { PhysicsServer3D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode(); switch (mode) { @@ -493,8 +505,8 @@ void GodotBody3D::integrate_forces(real_t p_step) { case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE: case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: { gravity = Vector3(0, 0, 0); - area_angular_damp = 0; - area_linear_damp = 0; + total_linear_damp = 0.0; + total_angular_damp = 0.0; _compute_area_gravity_and_damping(aa[i].area); stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE; } break; @@ -504,29 +516,36 @@ void GodotBody3D::integrate_forces(real_t p_step) { } } + // Add default gravity and damping from space area. if (!stopped) { + GodotArea3D *def_area = get_space()->get_default_area(); + ERR_FAIL_COND(!def_area); + _compute_area_gravity_and_damping(def_area); } + // Override linear damping with body's value. + switch (linear_damp_mode) { + case PhysicsServer3D::BODY_DAMP_MODE_COMBINE: { + total_linear_damp += linear_damp; + } break; + case PhysicsServer3D::BODY_DAMP_MODE_REPLACE: { + total_linear_damp = linear_damp; + } break; + } + + // Override angular damping with body's value. + switch (angular_damp_mode) { + case PhysicsServer3D::BODY_DAMP_MODE_COMBINE: { + total_angular_damp += angular_damp; + } break; + case PhysicsServer3D::BODY_DAMP_MODE_REPLACE: { + total_angular_damp = angular_damp; + } break; + } + gravity *= gravity_scale; - // If less than 0, override dampenings with that of the Body - if (angular_damp >= 0) { - area_angular_damp = angular_damp; - } - /* - else - area_angular_damp=damp_area->get_angular_damp(); - */ - - if (linear_damp >= 0) { - area_linear_damp = linear_damp; - } - /* - else - area_linear_damp=damp_area->get_linear_damp(); - */ - Vector3 motion; bool do_motion = false; @@ -552,13 +571,13 @@ void GodotBody3D::integrate_forces(real_t p_step) { force += applied_force; Vector3 torque = applied_torque; - real_t damp = 1.0 - p_step * area_linear_damp; + real_t damp = 1.0 - p_step * total_linear_damp; if (damp < 0) { // reached zero in the given time damp = 0; } - real_t angular_damp = 1.0 - p_step * area_angular_damp; + real_t angular_damp = 1.0 - p_step * total_angular_damp; if (angular_damp < 0) { // reached zero in the given time angular_damp = 0; @@ -580,8 +599,6 @@ void GodotBody3D::integrate_forces(real_t p_step) { applied_force = Vector3(); applied_torque = Vector3(); - //motion=linear_velocity*p_step; - biased_angular_velocity = Vector3(); biased_linear_velocity = Vector3(); @@ -589,7 +606,6 @@ void GodotBody3D::integrate_forces(real_t p_step) { _update_shapes_with_motion(motion); } - def_area = nullptr; // clear the area, so it is set in the next frame contact_count = 0; } diff --git a/servers/physics_3d/godot_body_3d.h b/servers/physics_3d/godot_body_3d.h index 5acdab9d13..4993ea6a1b 100644 --- a/servers/physics_3d/godot_body_3d.h +++ b/servers/physics_3d/godot_body_3d.h @@ -55,8 +55,15 @@ class GodotBody3D : public GodotCollisionObject3D { real_t friction = 1.0; Vector3 inertia; - real_t linear_damp = -1.0; - real_t angular_damp = -1.0; + PhysicsServer3D::BodyDampMode linear_damp_mode = PhysicsServer3D::BODY_DAMP_MODE_COMBINE; + PhysicsServer3D::BodyDampMode angular_damp_mode = PhysicsServer3D::BODY_DAMP_MODE_COMBINE; + + real_t linear_damp = 0.0; + real_t angular_damp = 0.0; + + real_t total_linear_damp = 0.0; + real_t total_angular_damp = 0.0; + real_t gravity_scale = 1.0; uint16_t locked_axis = 0; @@ -83,9 +90,6 @@ class GodotBody3D : public GodotCollisionObject3D { Vector3 applied_force; Vector3 applied_torque; - real_t area_angular_damp = 0.0; - real_t area_linear_damp = 0.0; - SelfList active_list; SelfList mass_properties_update_list; SelfList direct_state_query_list; @@ -285,7 +289,6 @@ public: _FORCE_INLINE_ const Vector3 &get_inv_inertia() const { return _inv_inertia; } _FORCE_INLINE_ const Basis &get_inv_inertia_tensor() const { return _inv_inertia_tensor; } _FORCE_INLINE_ real_t get_friction() const { return friction; } - _FORCE_INLINE_ const Vector3 &get_gravity() const { return gravity; } _FORCE_INLINE_ real_t get_bounce() const { return bounce; } void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock); diff --git a/servers/physics_3d/godot_body_direct_state_3d.cpp b/servers/physics_3d/godot_body_direct_state_3d.cpp index db09657f8a..9c234a5752 100644 --- a/servers/physics_3d/godot_body_direct_state_3d.cpp +++ b/servers/physics_3d/godot_body_direct_state_3d.cpp @@ -38,11 +38,11 @@ Vector3 GodotPhysicsDirectBodyState3D::get_total_gravity() const { } real_t GodotPhysicsDirectBodyState3D::get_total_angular_damp() const { - return body->area_angular_damp; + return body->total_angular_damp; } real_t GodotPhysicsDirectBodyState3D::get_total_linear_damp() const { - return body->area_linear_damp; + return body->total_linear_damp; } Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass() const { diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index a6cb7dbdd9..300f9c7d8b 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -758,10 +758,15 @@ void PhysicsServer2D::_bind_methods() { BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA); BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS); BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE); + BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP_MODE); + BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP_MODE); BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP); BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP); BIND_ENUM_CONSTANT(BODY_PARAM_MAX); + BIND_ENUM_CONSTANT(BODY_DAMP_MODE_COMBINE); + BIND_ENUM_CONSTANT(BODY_DAMP_MODE_REPLACE); + BIND_ENUM_CONSTANT(BODY_STATE_TRANSFORM); BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY); BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY); diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index f83c57407d..584da56c66 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -400,11 +400,18 @@ public: BODY_PARAM_INERTIA, BODY_PARAM_CENTER_OF_MASS, BODY_PARAM_GRAVITY_SCALE, + BODY_PARAM_LINEAR_DAMP_MODE, + BODY_PARAM_ANGULAR_DAMP_MODE, BODY_PARAM_LINEAR_DAMP, BODY_PARAM_ANGULAR_DAMP, BODY_PARAM_MAX, }; + enum BodyDampMode { + BODY_DAMP_MODE_COMBINE, + BODY_DAMP_MODE_REPLACE, + }; + virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) = 0; virtual Variant body_get_param(RID p_body, BodyParameter p_param) const = 0; @@ -692,12 +699,12 @@ VARIANT_ENUM_CAST(PhysicsServer2D::AreaParameter); VARIANT_ENUM_CAST(PhysicsServer2D::AreaSpaceOverrideMode); VARIANT_ENUM_CAST(PhysicsServer2D::BodyMode); VARIANT_ENUM_CAST(PhysicsServer2D::BodyParameter); +VARIANT_ENUM_CAST(PhysicsServer2D::BodyDampMode); VARIANT_ENUM_CAST(PhysicsServer2D::BodyState); VARIANT_ENUM_CAST(PhysicsServer2D::CCDMode); VARIANT_ENUM_CAST(PhysicsServer2D::JointParam); VARIANT_ENUM_CAST(PhysicsServer2D::JointType); VARIANT_ENUM_CAST(PhysicsServer2D::DampedSpringParam); -//VARIANT_ENUM_CAST( PhysicsServer2D::ObjectType ); VARIANT_ENUM_CAST(PhysicsServer2D::AreaBodyStatus); VARIANT_ENUM_CAST(PhysicsServer2D::ProcessInfo); diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index 90922cc250..c68cd7696b 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -863,10 +863,15 @@ void PhysicsServer3D::_bind_methods() { BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA); BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS); BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE); + BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP_MODE); + BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP_MODE); BIND_ENUM_CONSTANT(BODY_PARAM_LINEAR_DAMP); BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP); BIND_ENUM_CONSTANT(BODY_PARAM_MAX); + BIND_ENUM_CONSTANT(BODY_DAMP_MODE_COMBINE); + BIND_ENUM_CONSTANT(BODY_DAMP_MODE_REPLACE); + BIND_ENUM_CONSTANT(BODY_STATE_TRANSFORM); BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY); BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY); diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index 6f55e287c9..79369bd459 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -364,6 +364,11 @@ public: BODY_MODE_DYNAMIC_LINEAR, }; + enum BodyDampMode { + BODY_DAMP_MODE_COMBINE, + BODY_DAMP_MODE_REPLACE, + }; + virtual RID body_create() = 0; virtual void body_set_space(RID p_body, RID p_space) = 0; @@ -408,6 +413,8 @@ public: BODY_PARAM_INERTIA, BODY_PARAM_CENTER_OF_MASS, BODY_PARAM_GRAVITY_SCALE, + BODY_PARAM_LINEAR_DAMP_MODE, + BODY_PARAM_ANGULAR_DAMP_MODE, BODY_PARAM_LINEAR_DAMP, BODY_PARAM_ANGULAR_DAMP, BODY_PARAM_MAX, @@ -890,6 +897,7 @@ VARIANT_ENUM_CAST(PhysicsServer3D::AreaParameter); VARIANT_ENUM_CAST(PhysicsServer3D::AreaSpaceOverrideMode); VARIANT_ENUM_CAST(PhysicsServer3D::BodyMode); VARIANT_ENUM_CAST(PhysicsServer3D::BodyParameter); +VARIANT_ENUM_CAST(PhysicsServer3D::BodyDampMode); VARIANT_ENUM_CAST(PhysicsServer3D::BodyState); VARIANT_ENUM_CAST(PhysicsServer3D::BodyAxis); VARIANT_ENUM_CAST(PhysicsServer3D::PinJointParam);