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).
This commit is contained in:
PouleyKetchoupp 2020-04-14 19:59:53 +02:00
parent 24fdedfe94
commit daf7dcac7a
20 changed files with 382 additions and 127 deletions

View File

@ -37,8 +37,12 @@
</method> </method>
</methods> </methods>
<members> <members>
<member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="-1.0"> <member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="0.0">
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 &gt; Project Settings &gt; Physics &gt; 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.
</member>
<member name="angular_damp_mode" type="int" setter="set_angular_damp_mode" getter="get_angular_damp_mode" enum="PhysicalBone3D.DampMode" default="0">
Defines how [member angular_damp] is applied. See [enum DampMode] for possible values.
</member> </member>
<member name="body_offset" type="Transform3D" setter="set_body_offset" getter="get_body_offset" default="Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)"> <member name="body_offset" type="Transform3D" setter="set_body_offset" getter="get_body_offset" default="Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)">
Sets the body's transform. Sets the body's transform.
@ -64,14 +68,24 @@
<member name="joint_type" type="int" setter="set_joint_type" getter="get_joint_type" enum="PhysicalBone3D.JointType" default="0"> <member name="joint_type" type="int" setter="set_joint_type" getter="get_joint_type" enum="PhysicalBone3D.JointType" default="0">
Sets the joint type. See [enum JointType] for possible values. Sets the joint type. See [enum JointType] for possible values.
</member> </member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="-1.0"> <member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.0">
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 &gt; Project Settings &gt; Physics &gt; 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.
</member>
<member name="linear_damp_mode" type="int" setter="set_linear_damp_mode" getter="get_linear_damp_mode" enum="PhysicalBone3D.DampMode" default="0">
Defines how [member linear_damp] is applied. See [enum DampMode] for possible values.
</member> </member>
<member name="mass" type="float" setter="set_mass" getter="get_mass" default="1.0"> <member name="mass" type="float" setter="set_mass" getter="get_mass" default="1.0">
The body's mass. The body's mass.
</member> </member>
</members> </members>
<constants> <constants>
<constant name="DAMP_MODE_COMBINE" value="0" enum="DampMode">
In this mode, the body's damping value is added to any value set in areas or the default value.
</constant>
<constant name="DAMP_MODE_REPLACE" value="1" enum="DampMode">
In this mode, the body's damping value replaces any value set in areas or the default value.
</constant>
<constant name="JOINT_TYPE_NONE" value="0" enum="JointType"> <constant name="JOINT_TYPE_NONE" value="0" enum="JointType">
</constant> </constant>
<constant name="JOINT_TYPE_PIN" value="1" enum="JointType"> <constant name="JOINT_TYPE_PIN" value="1" enum="JointType">

View File

@ -926,15 +926,27 @@
<constant name="BODY_PARAM_GRAVITY_SCALE" value="5" enum="BodyParameter"> <constant name="BODY_PARAM_GRAVITY_SCALE" value="5" enum="BodyParameter">
Constant to set/get a body's gravity multiplier. Constant to set/get a body's gravity multiplier.
</constant> </constant>
<constant name="BODY_PARAM_LINEAR_DAMP" value="6" enum="BodyParameter"> <constant name="BODY_PARAM_LINEAR_DAMP_MODE" value="6" enum="BodyParameter">
Constant to set/get a body's linear dampening mode. See [enum BodyDampMode] for possible values.
</constant>
<constant name="BODY_PARAM_ANGULAR_DAMP_MODE" value="7" enum="BodyParameter">
Constant to set/get a body's angular dampening mode. See [enum BodyDampMode] for possible values.
</constant>
<constant name="BODY_PARAM_LINEAR_DAMP" value="8" enum="BodyParameter">
Constant to set/get a body's linear dampening factor. Constant to set/get a body's linear dampening factor.
</constant> </constant>
<constant name="BODY_PARAM_ANGULAR_DAMP" value="7" enum="BodyParameter"> <constant name="BODY_PARAM_ANGULAR_DAMP" value="9" enum="BodyParameter">
Constant to set/get a body's angular dampening factor. Constant to set/get a body's angular dampening factor.
</constant> </constant>
<constant name="BODY_PARAM_MAX" value="8" enum="BodyParameter"> <constant name="BODY_PARAM_MAX" value="10" enum="BodyParameter">
Represents the size of the [enum BodyParameter] enum. Represents the size of the [enum BodyParameter] enum.
</constant> </constant>
<constant name="BODY_DAMP_MODE_COMBINE" value="0" enum="BodyDampMode">
The body's damping value is added to any value set in areas or the default value.
</constant>
<constant name="BODY_DAMP_MODE_REPLACE" value="1" enum="BodyDampMode">
The body's damping value replaces any value set in areas or the default value.
</constant>
<constant name="BODY_STATE_TRANSFORM" value="0" enum="BodyState"> <constant name="BODY_STATE_TRANSFORM" value="0" enum="BodyState">
Constant to set/get the current transform matrix of the body. Constant to set/get the current transform matrix of the body.
</constant> </constant>

View File

@ -1294,15 +1294,27 @@
<constant name="BODY_PARAM_GRAVITY_SCALE" value="5" enum="BodyParameter"> <constant name="BODY_PARAM_GRAVITY_SCALE" value="5" enum="BodyParameter">
Constant to set/get a body's gravity multiplier. Constant to set/get a body's gravity multiplier.
</constant> </constant>
<constant name="BODY_PARAM_LINEAR_DAMP" value="6" enum="BodyParameter"> <constant name="BODY_PARAM_LINEAR_DAMP_MODE" value="6" enum="BodyParameter">
Constant to set/get a body's linear dampening mode. See [enum BodyDampMode] for possible values.
</constant>
<constant name="BODY_PARAM_ANGULAR_DAMP_MODE" value="7" enum="BodyParameter">
Constant to set/get a body's angular dampening mode. See [enum BodyDampMode] for possible values.
</constant>
<constant name="BODY_PARAM_LINEAR_DAMP" value="8" enum="BodyParameter">
Constant to set/get a body's linear dampening factor. Constant to set/get a body's linear dampening factor.
</constant> </constant>
<constant name="BODY_PARAM_ANGULAR_DAMP" value="7" enum="BodyParameter"> <constant name="BODY_PARAM_ANGULAR_DAMP" value="9" enum="BodyParameter">
Constant to set/get a body's angular dampening factor. Constant to set/get a body's angular dampening factor.
</constant> </constant>
<constant name="BODY_PARAM_MAX" value="8" enum="BodyParameter"> <constant name="BODY_PARAM_MAX" value="10" enum="BodyParameter">
Represents the size of the [enum BodyParameter] enum. Represents the size of the [enum BodyParameter] enum.
</constant> </constant>
<constant name="BODY_DAMP_MODE_COMBINE" value="0" enum="BodyDampMode">
The body's damping value is added to any value set in areas or the default value.
</constant>
<constant name="BODY_DAMP_MODE_REPLACE" value="1" enum="BodyDampMode">
The body's damping value replaces any value set in areas or the default value.
</constant>
<constant name="BODY_STATE_TRANSFORM" value="0" enum="BodyState"> <constant name="BODY_STATE_TRANSFORM" value="0" enum="BodyState">
Constant to set/get the current transform matrix of the body. Constant to set/get the current transform matrix of the body.
</constant> </constant>

View File

@ -82,10 +82,13 @@
</method> </method>
</methods> </methods>
<members> <members>
<member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="-1.0"> <member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="0.0">
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 &gt; Project Settings &gt; Physics &gt; 2d[/b]. Damps the body's rotation. By default, the body will use the [b]Default Angular Damp[/b] in [b]Project &gt; Project Settings &gt; Physics &gt; 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. See [member ProjectSettings.physics/2d/default_angular_damp] for more details about damping.
</member> </member>
<member name="angular_damp_mode" type="int" setter="set_angular_damp_mode" getter="get_angular_damp_mode" enum="RigidDynamicBody2D.DampMode" default="0">
Defines how [member angular_damp] is applied. See [enum DampMode] for possible values.
</member>
<member name="angular_velocity" type="float" setter="set_angular_velocity" getter="get_angular_velocity" default="0.0"> <member name="angular_velocity" type="float" setter="set_angular_velocity" getter="get_angular_velocity" default="0.0">
The body's rotational velocity. The body's rotational velocity.
</member> </member>
@ -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. 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). If set to [code]0[/code], inertia is automatically computed (default value).
</member> </member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="-1.0"> <member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.0">
Damps the body's [member linear_velocity]. If [code]-1[/code], the body will use the [b]Default Linear Damp[/b] in [b]Project &gt; Project Settings &gt; Physics &gt; 2d[/b]. Damps the body's movement. By default, the body will use the [b]Default Linear Damp[/b] in [b]Project &gt; Project Settings &gt; Physics &gt; 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. See [member ProjectSettings.physics/2d/default_linear_damp] for more details about damping.
</member> </member>
<member name="linear_damp_mode" type="int" setter="set_linear_damp_mode" getter="get_linear_damp_mode" enum="RigidDynamicBody2D.DampMode" default="0">
Defines how [member linear_damp] is applied. See [enum DampMode] for possible values.
</member>
<member name="linear_velocity" type="Vector2" setter="set_linear_velocity" getter="get_linear_velocity" default="Vector2(0, 0)"> <member name="linear_velocity" type="Vector2" setter="set_linear_velocity" getter="get_linear_velocity" default="Vector2(0, 0)">
The body's linear velocity. The body's linear velocity.
</member> </member>
@ -217,6 +223,12 @@
<constant name="CENTER_OF_MASS_MODE_CUSTOM" value="1" enum="CenterOfMassMode"> <constant name="CENTER_OF_MASS_MODE_CUSTOM" value="1" enum="CenterOfMassMode">
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 center of mass is set through [member center_of_mass]. Defaults to the body's origin position.
</constant> </constant>
<constant name="DAMP_MODE_COMBINE" value="0" enum="DampMode">
In this mode, the body's damping value is added to any value set in areas or the default value.
</constant>
<constant name="DAMP_MODE_REPLACE" value="1" enum="DampMode">
In this mode, the body's damping value replaces any value set in areas or the default value.
</constant>
<constant name="CCD_MODE_DISABLED" value="0" enum="CCDMode"> <constant name="CCD_MODE_DISABLED" value="0" enum="CCDMode">
Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects. Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
</constant> </constant>

View File

@ -91,10 +91,13 @@
</method> </method>
</methods> </methods>
<members> <members>
<member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="-1.0"> <member name="angular_damp" type="float" setter="set_angular_damp" getter="get_angular_damp" default="0.0">
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 &gt; Project Settings &gt; Physics &gt; 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. See [member ProjectSettings.physics/3d/default_angular_damp] for more details about damping.
</member> </member>
<member name="angular_damp_mode" type="int" setter="set_angular_damp_mode" getter="get_angular_damp_mode" enum="RigidDynamicBody3D.DampMode" default="0">
Defines how [member angular_damp] is applied. See [enum DampMode] for possible values.
</member>
<member name="angular_velocity" type="Vector3" setter="set_angular_velocity" getter="get_angular_velocity" default="Vector3(0, 0, 0)"> <member name="angular_velocity" type="Vector3" setter="set_angular_velocity" getter="get_angular_velocity" default="Vector3(0, 0, 0)">
RigidDynamicBody3D's rotational velocity. RigidDynamicBody3D's rotational velocity.
</member> </member>
@ -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. 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). If set to [code]Vector3.ZERO[/code], inertia is automatically computed (default value).
</member> </member>
<member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="-1.0"> <member name="linear_damp" type="float" setter="set_linear_damp" getter="get_linear_damp" default="0.0">
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 &gt; Project Settings &gt; Physics &gt; 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. See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping.
</member> </member>
<member name="linear_damp_mode" type="int" setter="set_linear_damp_mode" getter="get_linear_damp_mode" enum="RigidDynamicBody3D.DampMode" default="0">
Defines how [member linear_damp] is applied. See [enum DampMode] for possible values.
</member>
<member name="linear_velocity" type="Vector3" setter="set_linear_velocity" getter="get_linear_velocity" default="Vector3(0, 0, 0)"> <member name="linear_velocity" type="Vector3" setter="set_linear_velocity" getter="get_linear_velocity" default="Vector3(0, 0, 0)">
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. 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.
</member> </member>
@ -222,5 +228,11 @@
<constant name="CENTER_OF_MASS_MODE_CUSTOM" value="1" enum="CenterOfMassMode"> <constant name="CENTER_OF_MASS_MODE_CUSTOM" value="1" enum="CenterOfMassMode">
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 center of mass is set through [member center_of_mass]. Defaults to the body's origin position.
</constant> </constant>
<constant name="DAMP_MODE_COMBINE" value="0" enum="DampMode">
In this mode, the body's damping value is added to any value set in areas or the default value.
</constant>
<constant name="DAMP_MODE_REPLACE" value="1" enum="DampMode">
In this mode, the body's damping value replaces any value set in areas or the default value.
</constant>
</constants> </constants>
</class> </class>

View File

@ -684,6 +684,24 @@ real_t RigidDynamicBody2D::get_gravity_scale() const {
return gravity_scale; 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) { void RigidDynamicBody2D::set_linear_damp(real_t p_linear_damp) {
ERR_FAIL_COND(p_linear_damp < -1); ERR_FAIL_COND(p_linear_damp < -1);
linear_damp = p_linear_damp; 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("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("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("set_linear_damp", "linear_damp"), &RigidDynamicBody2D::set_linear_damp);
ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidDynamicBody2D::get_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_PROPERTY(PropertyInfo(Variant::INT, "freeze_mode", PROPERTY_HINT_ENUM, "Static,Kinematic"), "set_freeze_mode", "get_freeze_mode");
ADD_GROUP("Linear", "linear_"); ADD_GROUP("Linear", "linear_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "linear_velocity"), "set_linear_velocity", "get_linear_velocity"); 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_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_GROUP("Angular", "angular_");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_velocity"), "set_angular_velocity", "get_angular_velocity"); 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_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_GROUP("Applied Forces", "applied_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "applied_force"), "set_applied_force", "get_applied_force"); 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_AUTO);
BIND_ENUM_CONSTANT(CENTER_OF_MASS_MODE_CUSTOM); 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_DISABLED);
BIND_ENUM_CONSTANT(CCD_MODE_CAST_RAY); BIND_ENUM_CONSTANT(CCD_MODE_CAST_RAY);
BIND_ENUM_CONSTANT(CCD_MODE_CAST_SHAPE); BIND_ENUM_CONSTANT(CCD_MODE_CAST_SHAPE);

View File

@ -127,6 +127,11 @@ public:
CENTER_OF_MASS_MODE_CUSTOM, CENTER_OF_MASS_MODE_CUSTOM,
}; };
enum DampMode {
DAMP_MODE_COMBINE,
DAMP_MODE_REPLACE,
};
enum CCDMode { enum CCDMode {
CCD_MODE_DISABLED, CCD_MODE_DISABLED,
CCD_MODE_CAST_RAY, CCD_MODE_CAST_RAY,
@ -146,8 +151,12 @@ private:
Ref<PhysicsMaterial> physics_material_override; Ref<PhysicsMaterial> physics_material_override;
real_t gravity_scale = 1.0; 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; Vector2 linear_velocity;
real_t angular_velocity = 0.0; real_t angular_velocity = 0.0;
@ -241,6 +250,12 @@ public:
void set_gravity_scale(real_t p_gravity_scale); void set_gravity_scale(real_t p_gravity_scale);
real_t get_gravity_scale() const; 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); void set_linear_damp(real_t p_linear_damp);
real_t get_linear_damp() const; real_t get_linear_damp() const;
@ -300,6 +315,7 @@ private:
VARIANT_ENUM_CAST(RigidDynamicBody2D::FreezeMode); VARIANT_ENUM_CAST(RigidDynamicBody2D::FreezeMode);
VARIANT_ENUM_CAST(RigidDynamicBody2D::CenterOfMassMode); VARIANT_ENUM_CAST(RigidDynamicBody2D::CenterOfMassMode);
VARIANT_ENUM_CAST(RigidDynamicBody2D::DampMode);
VARIANT_ENUM_CAST(RigidDynamicBody2D::CCDMode); VARIANT_ENUM_CAST(RigidDynamicBody2D::CCDMode);
class CharacterBody2D : public PhysicsBody2D { class CharacterBody2D : public PhysicsBody2D {

View File

@ -758,8 +758,26 @@ real_t RigidDynamicBody3D::get_gravity_scale() const {
return gravity_scale; 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) { 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; linear_damp = p_linear_damp;
PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP, 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) { 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; angular_damp = p_angular_damp;
PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, 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("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("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("set_linear_damp", "linear_damp"), &RigidDynamicBody3D::set_linear_damp);
ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidDynamicBody3D::get_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_PROPERTY(PropertyInfo(Variant::INT, "freeze_mode", PROPERTY_HINT_ENUM, "Static,Kinematic"), "set_freeze_mode", "get_freeze_mode");
ADD_GROUP("Linear", "linear_"); ADD_GROUP("Linear", "linear_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity"); 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_GROUP("Angular", "angular_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "angular_velocity"), "set_angular_velocity", "get_angular_velocity"); 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_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"))); 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_AUTO);
BIND_ENUM_CONSTANT(CENTER_OF_MASS_MODE_CUSTOM); 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 { 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("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("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("set_linear_damp", "linear_damp"), &PhysicalBone3D::set_linear_damp);
ClassDB::bind_method(D_METHOD("get_linear_damp"), &PhysicalBone3D::get_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, "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, "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, "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::INT, "linear_damp_mode", PROPERTY_HINT_ENUM, "Combine,Replace"), "set_linear_damp_mode", "get_linear_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_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"); 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_NONE);
BIND_ENUM_CONSTANT(JOINT_TYPE_PIN); BIND_ENUM_CONSTANT(JOINT_TYPE_PIN);
BIND_ENUM_CONSTANT(JOINT_TYPE_CONE); BIND_ENUM_CONSTANT(JOINT_TYPE_CONE);
@ -3144,8 +3184,27 @@ real_t PhysicalBone3D::get_gravity_scale() const {
return gravity_scale; 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) { 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; linear_damp = p_linear_damp;
PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP, 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) { 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; angular_damp = p_angular_damp;
PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, angular_damp); PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, angular_damp);
} }

View File

@ -143,6 +143,11 @@ public:
CENTER_OF_MASS_MODE_CUSTOM, CENTER_OF_MASS_MODE_CUSTOM,
}; };
enum DampMode {
DAMP_MODE_COMBINE,
DAMP_MODE_REPLACE,
};
private: private:
bool can_sleep = true; bool can_sleep = true;
bool lock_rotation = false; bool lock_rotation = false;
@ -160,8 +165,12 @@ private:
Vector3 angular_velocity; Vector3 angular_velocity;
Basis inverse_inertia_tensor; Basis inverse_inertia_tensor;
real_t gravity_scale = 1.0; 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 sleeping = false;
bool ccd = false; bool ccd = false;
@ -265,6 +274,12 @@ public:
void set_gravity_scale(real_t p_gravity_scale); void set_gravity_scale(real_t p_gravity_scale);
real_t get_gravity_scale() const; 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); void set_linear_damp(real_t p_linear_damp);
real_t get_linear_damp() const; real_t get_linear_damp() const;
@ -310,6 +325,7 @@ private:
VARIANT_ENUM_CAST(RigidDynamicBody3D::FreezeMode); VARIANT_ENUM_CAST(RigidDynamicBody3D::FreezeMode);
VARIANT_ENUM_CAST(RigidDynamicBody3D::CenterOfMassMode); VARIANT_ENUM_CAST(RigidDynamicBody3D::CenterOfMassMode);
VARIANT_ENUM_CAST(RigidDynamicBody3D::DampMode);
class KinematicCollision3D; class KinematicCollision3D;
@ -494,6 +510,11 @@ class PhysicalBone3D : public PhysicsBody3D {
GDCLASS(PhysicalBone3D, PhysicsBody3D); GDCLASS(PhysicalBone3D, PhysicsBody3D);
public: public:
enum DampMode {
DAMP_MODE_COMBINE,
DAMP_MODE_REPLACE,
};
enum JointType { enum JointType {
JOINT_TYPE_NONE, JOINT_TYPE_NONE,
JOINT_TYPE_PIN, JOINT_TYPE_PIN,
@ -632,10 +653,14 @@ private:
real_t mass = 1.0; real_t mass = 1.0;
real_t friction = 1.0; real_t friction = 1.0;
real_t gravity_scale = 1.0; real_t gravity_scale = 1.0;
real_t linear_damp = -1.0;
real_t angular_damp = -1.0;
bool can_sleep = true; 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: protected:
bool _set(const StringName &p_name, const Variant &p_value); bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const; bool _get(const StringName &p_name, Variant &r_ret) const;
@ -698,6 +723,12 @@ public:
void set_gravity_scale(real_t p_gravity_scale); void set_gravity_scale(real_t p_gravity_scale);
real_t get_gravity_scale() const; 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); void set_linear_damp(real_t p_linear_damp);
real_t get_linear_damp() const; real_t get_linear_damp() const;
@ -725,5 +756,6 @@ private:
}; };
VARIANT_ENUM_CAST(PhysicalBone3D::JointType); VARIANT_ENUM_CAST(PhysicalBone3D::JointType);
VARIANT_ENUM_CAST(PhysicalBone3D::DampMode);
#endif // PHYSICS_BODY__H #endif // PHYSICS_BODY__H

View File

@ -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, 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_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)); 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)); 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(); navigation_map = NavigationServer3D::get_singleton()->map_create();
NavigationServer3D::get_singleton()->map_set_active(navigation_map, true); NavigationServer3D::get_singleton()->map_set_active(navigation_map, true);

View File

@ -187,6 +187,14 @@ void GodotBody2D::set_param(PhysicsServer2D::BodyParameter p_param, const Varian
case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: { case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: {
gravity_scale = p_value; gravity_scale = p_value;
} break; } 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: { case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP: {
linear_damp = p_value; linear_damp = p_value;
} break; } break;
@ -218,6 +226,12 @@ Variant GodotBody2D::get_param(PhysicsServer2D::BodyParameter p_param) const {
case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: { case PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE: {
return 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: { case PhysicsServer2D::BODY_PARAM_LINEAR_DAMP: {
return 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); p_area->compute_gravity(get_transform().get_origin(), area_gravity);
gravity += area_gravity; gravity += area_gravity;
area_linear_damp += p_area->get_linear_damp(); total_linear_damp += p_area->get_linear_damp();
area_angular_damp += p_area->get_angular_damp(); total_angular_damp += p_area->get_angular_damp();
} }
void GodotBody2D::_update_transform_dependent() { void GodotBody2D::_update_transform_dependent() {
@ -414,19 +428,17 @@ void GodotBody2D::integrate_forces(real_t p_step) {
return; return;
} }
GodotArea2D *def_area = get_space()->get_default_area();
// GodotArea2D *damp_area = def_area;
ERR_FAIL_COND(!def_area);
int ac = areas.size(); int ac = areas.size();
bool stopped = false; bool stopped = false;
gravity = Vector2(0, 0); 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) { if (ac) {
areas.sort(); areas.sort();
const AreaCMP *aa = &areas[0]; const AreaCMP *aa = &areas[0];
// damp_area = aa[ac-1].area;
for (int i = ac - 1; i >= 0 && !stopped; i--) { for (int i = ac - 1; i >= 0 && !stopped; i--) {
PhysicsServer2D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode(); PhysicsServer2D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode();
switch (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:
case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: { case PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
gravity = Vector2(0, 0); gravity = Vector2(0, 0);
area_angular_damp = 0; total_linear_damp = 0.0;
area_linear_damp = 0; total_angular_damp = 0.0;
_compute_area_gravity_and_damping(aa[i].area); _compute_area_gravity_and_damping(aa[i].area);
stopped = mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE; stopped = mode == PhysicsServer2D::AREA_SPACE_OVERRIDE_REPLACE;
} break; } break;
@ -448,28 +460,37 @@ void GodotBody2D::integrate_forces(real_t p_step) {
} }
} }
} }
// Override linear damping with body's value.
if (!stopped) { if (!stopped) {
GodotArea2D *def_area = get_space()->get_default_area();
ERR_FAIL_COND(!def_area);
_compute_area_gravity_and_damping(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; 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; Vector2 motion;
bool do_motion = false; bool do_motion = false;
@ -483,13 +504,6 @@ void GodotBody2D::integrate_forces(real_t p_step) {
do_motion = true; do_motion = true;
/*
for(int i=0;i<get_shape_count();i++) {
set_shape_kinematic_advance(i,Vector2());
set_shape_kinematic_retreat(i,0);
}
*/
} else { } else {
if (!omit_force_integration) { if (!omit_force_integration) {
//overridden by direct state query //overridden by direct state query
@ -498,13 +512,13 @@ void GodotBody2D::integrate_forces(real_t p_step) {
force += applied_force; force += applied_force;
real_t torque = applied_torque; real_t 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 if (damp < 0) { // reached zero in the given time
damp = 0; 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 if (angular_damp < 0) { // reached zero in the given time
angular_damp = 0; angular_damp = 0;
@ -523,8 +537,6 @@ void GodotBody2D::integrate_forces(real_t p_step) {
} }
} }
//motion=linear_velocity*p_step;
biased_angular_velocity = 0; biased_angular_velocity = 0;
biased_linear_velocity = Vector2(); biased_linear_velocity = Vector2();
@ -532,8 +544,6 @@ void GodotBody2D::integrate_forces(real_t p_step) {
_update_shapes_with_motion(motion); _update_shapes_with_motion(motion);
} }
// damp_area=nullptr; // clear the area, so it is set in the next frame
def_area = nullptr; // clear the area, so it is set in the next frame
contact_count = 0; contact_count = 0;
} }

View File

@ -53,8 +53,15 @@ class GodotBody2D : public GodotCollisionObject2D {
Vector2 constant_linear_velocity; Vector2 constant_linear_velocity;
real_t constant_angular_velocity = 0.0; real_t constant_angular_velocity = 0.0;
real_t linear_damp = -1.0; PhysicsServer2D::BodyDampMode linear_damp_mode = PhysicsServer2D::BODY_DAMP_MODE_COMBINE;
real_t angular_damp = -1.0; PhysicsServer2D::BodyDampMode angular_damp_mode = PhysicsServer2D::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; real_t gravity_scale = 1.0;
real_t bounce = 0.0; real_t bounce = 0.0;
@ -73,8 +80,6 @@ class GodotBody2D : public GodotCollisionObject2D {
bool calculate_center_of_mass = true; bool calculate_center_of_mass = true;
Vector2 gravity; Vector2 gravity;
real_t area_linear_damp = 0.0;
real_t area_angular_damp = 0.0;
real_t still_time = 0.0; real_t still_time = 0.0;
@ -276,14 +281,11 @@ public:
void update_mass_properties(); void update_mass_properties();
void reset_mass_properties(); void reset_mass_properties();
_FORCE_INLINE_ Vector2 get_center_of_mass() const { return center_of_mass; } _FORCE_INLINE_ const Vector2 &get_center_of_mass() const { return center_of_mass; }
_FORCE_INLINE_ real_t get_inv_mass() const { return _inv_mass; } _FORCE_INLINE_ real_t get_inv_mass() const { return _inv_mass; }
_FORCE_INLINE_ real_t get_inv_inertia() const { return _inv_inertia; } _FORCE_INLINE_ real_t get_inv_inertia() const { return _inv_inertia; }
_FORCE_INLINE_ real_t get_friction() const { return friction; } _FORCE_INLINE_ real_t get_friction() const { return friction; }
_FORCE_INLINE_ Vector2 get_gravity() const { return gravity; }
_FORCE_INLINE_ real_t get_bounce() const { return bounce; } _FORCE_INLINE_ real_t get_bounce() const { return bounce; }
_FORCE_INLINE_ real_t get_linear_damp() const { return linear_damp; }
_FORCE_INLINE_ real_t get_angular_damp() const { return angular_damp; }
void integrate_forces(real_t p_step); void integrate_forces(real_t p_step);
void integrate_velocities(real_t p_step); void integrate_velocities(real_t p_step);

View File

@ -39,11 +39,11 @@ Vector2 GodotPhysicsDirectBodyState2D::get_total_gravity() const {
} }
real_t GodotPhysicsDirectBodyState2D::get_total_angular_damp() const { real_t GodotPhysicsDirectBodyState2D::get_total_angular_damp() const {
return body->area_angular_damp; return body->total_angular_damp;
} }
real_t GodotPhysicsDirectBodyState2D::get_total_linear_damp() const { 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 { Vector2 GodotPhysicsDirectBodyState2D::get_center_of_mass() const {

View File

@ -229,6 +229,14 @@ void GodotBody3D::set_param(PhysicsServer3D::BodyParameter p_param, const Varian
case PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE: { case PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE: {
gravity_scale = p_value; gravity_scale = p_value;
} break; } 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: { case PhysicsServer3D::BODY_PARAM_LINEAR_DAMP: {
linear_damp = p_value; linear_damp = p_value;
} break; } break;
@ -264,6 +272,12 @@ Variant GodotBody3D::get_param(PhysicsServer3D::BodyParameter p_param) const {
case PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE: { case PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE: {
return gravity_scale; return gravity_scale;
} break; } 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: { case PhysicsServer3D::BODY_PARAM_LINEAR_DAMP: {
return linear_damp; return linear_damp;
} break; } 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); p_area->compute_gravity(get_transform().get_origin(), area_gravity);
gravity += area_gravity; gravity += area_gravity;
area_linear_damp += p_area->get_linear_damp(); total_linear_damp += p_area->get_linear_damp();
area_angular_damp += p_area->get_angular_damp(); total_angular_damp += p_area->get_angular_damp();
} }
void GodotBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock) { void GodotBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock) {
@ -469,19 +483,17 @@ void GodotBody3D::integrate_forces(real_t p_step) {
return; return;
} }
GodotArea3D *def_area = get_space()->get_default_area();
ERR_FAIL_COND(!def_area);
int ac = areas.size(); int ac = areas.size();
bool stopped = false; bool stopped = false;
gravity = Vector3(0, 0, 0); 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) { if (ac) {
areas.sort(); areas.sort();
const AreaCMP *aa = &areas[0]; const AreaCMP *aa = &areas[0];
// damp_area = aa[ac-1].area;
for (int i = ac - 1; i >= 0 && !stopped; i--) { for (int i = ac - 1; i >= 0 && !stopped; i--) {
PhysicsServer3D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode(); PhysicsServer3D::AreaSpaceOverrideMode mode = aa[i].area->get_space_override_mode();
switch (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:
case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: { case PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE_COMBINE: {
gravity = Vector3(0, 0, 0); gravity = Vector3(0, 0, 0);
area_angular_damp = 0; total_linear_damp = 0.0;
area_linear_damp = 0; total_angular_damp = 0.0;
_compute_area_gravity_and_damping(aa[i].area); _compute_area_gravity_and_damping(aa[i].area);
stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE; stopped = mode == PhysicsServer3D::AREA_SPACE_OVERRIDE_REPLACE;
} break; } break;
@ -504,29 +516,36 @@ void GodotBody3D::integrate_forces(real_t p_step) {
} }
} }
// Add default gravity and damping from space area.
if (!stopped) { if (!stopped) {
GodotArea3D *def_area = get_space()->get_default_area();
ERR_FAIL_COND(!def_area);
_compute_area_gravity_and_damping(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; 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; Vector3 motion;
bool do_motion = false; bool do_motion = false;
@ -552,13 +571,13 @@ void GodotBody3D::integrate_forces(real_t p_step) {
force += applied_force; force += applied_force;
Vector3 torque = applied_torque; 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 if (damp < 0) { // reached zero in the given time
damp = 0; 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 if (angular_damp < 0) { // reached zero in the given time
angular_damp = 0; angular_damp = 0;
@ -580,8 +599,6 @@ void GodotBody3D::integrate_forces(real_t p_step) {
applied_force = Vector3(); applied_force = Vector3();
applied_torque = Vector3(); applied_torque = Vector3();
//motion=linear_velocity*p_step;
biased_angular_velocity = Vector3(); biased_angular_velocity = Vector3();
biased_linear_velocity = Vector3(); biased_linear_velocity = Vector3();
@ -589,7 +606,6 @@ void GodotBody3D::integrate_forces(real_t p_step) {
_update_shapes_with_motion(motion); _update_shapes_with_motion(motion);
} }
def_area = nullptr; // clear the area, so it is set in the next frame
contact_count = 0; contact_count = 0;
} }

View File

@ -55,8 +55,15 @@ class GodotBody3D : public GodotCollisionObject3D {
real_t friction = 1.0; real_t friction = 1.0;
Vector3 inertia; Vector3 inertia;
real_t linear_damp = -1.0; PhysicsServer3D::BodyDampMode linear_damp_mode = PhysicsServer3D::BODY_DAMP_MODE_COMBINE;
real_t angular_damp = -1.0; 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; real_t gravity_scale = 1.0;
uint16_t locked_axis = 0; uint16_t locked_axis = 0;
@ -83,9 +90,6 @@ class GodotBody3D : public GodotCollisionObject3D {
Vector3 applied_force; Vector3 applied_force;
Vector3 applied_torque; Vector3 applied_torque;
real_t area_angular_damp = 0.0;
real_t area_linear_damp = 0.0;
SelfList<GodotBody3D> active_list; SelfList<GodotBody3D> active_list;
SelfList<GodotBody3D> mass_properties_update_list; SelfList<GodotBody3D> mass_properties_update_list;
SelfList<GodotBody3D> direct_state_query_list; SelfList<GodotBody3D> direct_state_query_list;
@ -285,7 +289,6 @@ public:
_FORCE_INLINE_ const Vector3 &get_inv_inertia() const { return _inv_inertia; } _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_ const Basis &get_inv_inertia_tensor() const { return _inv_inertia_tensor; }
_FORCE_INLINE_ real_t get_friction() const { return friction; } _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; } _FORCE_INLINE_ real_t get_bounce() const { return bounce; }
void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock); void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool lock);

View File

@ -38,11 +38,11 @@ Vector3 GodotPhysicsDirectBodyState3D::get_total_gravity() const {
} }
real_t GodotPhysicsDirectBodyState3D::get_total_angular_damp() 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 { 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 { Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass() const {

View File

@ -758,10 +758,15 @@ void PhysicsServer2D::_bind_methods() {
BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA); BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA);
BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS); BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS);
BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE); 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_LINEAR_DAMP);
BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP); BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP);
BIND_ENUM_CONSTANT(BODY_PARAM_MAX); 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_TRANSFORM);
BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY); BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY);
BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY); BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY);

View File

@ -400,11 +400,18 @@ public:
BODY_PARAM_INERTIA, BODY_PARAM_INERTIA,
BODY_PARAM_CENTER_OF_MASS, BODY_PARAM_CENTER_OF_MASS,
BODY_PARAM_GRAVITY_SCALE, BODY_PARAM_GRAVITY_SCALE,
BODY_PARAM_LINEAR_DAMP_MODE,
BODY_PARAM_ANGULAR_DAMP_MODE,
BODY_PARAM_LINEAR_DAMP, BODY_PARAM_LINEAR_DAMP,
BODY_PARAM_ANGULAR_DAMP, BODY_PARAM_ANGULAR_DAMP,
BODY_PARAM_MAX, 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 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; 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::AreaSpaceOverrideMode);
VARIANT_ENUM_CAST(PhysicsServer2D::BodyMode); VARIANT_ENUM_CAST(PhysicsServer2D::BodyMode);
VARIANT_ENUM_CAST(PhysicsServer2D::BodyParameter); VARIANT_ENUM_CAST(PhysicsServer2D::BodyParameter);
VARIANT_ENUM_CAST(PhysicsServer2D::BodyDampMode);
VARIANT_ENUM_CAST(PhysicsServer2D::BodyState); VARIANT_ENUM_CAST(PhysicsServer2D::BodyState);
VARIANT_ENUM_CAST(PhysicsServer2D::CCDMode); VARIANT_ENUM_CAST(PhysicsServer2D::CCDMode);
VARIANT_ENUM_CAST(PhysicsServer2D::JointParam); VARIANT_ENUM_CAST(PhysicsServer2D::JointParam);
VARIANT_ENUM_CAST(PhysicsServer2D::JointType); VARIANT_ENUM_CAST(PhysicsServer2D::JointType);
VARIANT_ENUM_CAST(PhysicsServer2D::DampedSpringParam); VARIANT_ENUM_CAST(PhysicsServer2D::DampedSpringParam);
//VARIANT_ENUM_CAST( PhysicsServer2D::ObjectType );
VARIANT_ENUM_CAST(PhysicsServer2D::AreaBodyStatus); VARIANT_ENUM_CAST(PhysicsServer2D::AreaBodyStatus);
VARIANT_ENUM_CAST(PhysicsServer2D::ProcessInfo); VARIANT_ENUM_CAST(PhysicsServer2D::ProcessInfo);

View File

@ -863,10 +863,15 @@ void PhysicsServer3D::_bind_methods() {
BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA); BIND_ENUM_CONSTANT(BODY_PARAM_INERTIA);
BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS); BIND_ENUM_CONSTANT(BODY_PARAM_CENTER_OF_MASS);
BIND_ENUM_CONSTANT(BODY_PARAM_GRAVITY_SCALE); 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_LINEAR_DAMP);
BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP); BIND_ENUM_CONSTANT(BODY_PARAM_ANGULAR_DAMP);
BIND_ENUM_CONSTANT(BODY_PARAM_MAX); 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_TRANSFORM);
BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY); BIND_ENUM_CONSTANT(BODY_STATE_LINEAR_VELOCITY);
BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY); BIND_ENUM_CONSTANT(BODY_STATE_ANGULAR_VELOCITY);

View File

@ -364,6 +364,11 @@ public:
BODY_MODE_DYNAMIC_LINEAR, BODY_MODE_DYNAMIC_LINEAR,
}; };
enum BodyDampMode {
BODY_DAMP_MODE_COMBINE,
BODY_DAMP_MODE_REPLACE,
};
virtual RID body_create() = 0; virtual RID body_create() = 0;
virtual void body_set_space(RID p_body, RID p_space) = 0; virtual void body_set_space(RID p_body, RID p_space) = 0;
@ -408,6 +413,8 @@ public:
BODY_PARAM_INERTIA, BODY_PARAM_INERTIA,
BODY_PARAM_CENTER_OF_MASS, BODY_PARAM_CENTER_OF_MASS,
BODY_PARAM_GRAVITY_SCALE, BODY_PARAM_GRAVITY_SCALE,
BODY_PARAM_LINEAR_DAMP_MODE,
BODY_PARAM_ANGULAR_DAMP_MODE,
BODY_PARAM_LINEAR_DAMP, BODY_PARAM_LINEAR_DAMP,
BODY_PARAM_ANGULAR_DAMP, BODY_PARAM_ANGULAR_DAMP,
BODY_PARAM_MAX, BODY_PARAM_MAX,
@ -890,6 +897,7 @@ VARIANT_ENUM_CAST(PhysicsServer3D::AreaParameter);
VARIANT_ENUM_CAST(PhysicsServer3D::AreaSpaceOverrideMode); VARIANT_ENUM_CAST(PhysicsServer3D::AreaSpaceOverrideMode);
VARIANT_ENUM_CAST(PhysicsServer3D::BodyMode); VARIANT_ENUM_CAST(PhysicsServer3D::BodyMode);
VARIANT_ENUM_CAST(PhysicsServer3D::BodyParameter); VARIANT_ENUM_CAST(PhysicsServer3D::BodyParameter);
VARIANT_ENUM_CAST(PhysicsServer3D::BodyDampMode);
VARIANT_ENUM_CAST(PhysicsServer3D::BodyState); VARIANT_ENUM_CAST(PhysicsServer3D::BodyState);
VARIANT_ENUM_CAST(PhysicsServer3D::BodyAxis); VARIANT_ENUM_CAST(PhysicsServer3D::BodyAxis);
VARIANT_ENUM_CAST(PhysicsServer3D::PinJointParam); VARIANT_ENUM_CAST(PhysicsServer3D::PinJointParam);