From 82ea2a7045e336bf4ce17358e2057558f89c3ac0 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Thu, 10 Jun 2021 17:37:19 -0700 Subject: Proper support for custom mass properties in 2D/3D physics bodies Changes: -Added support for custom inertia and center of mass in 3D -Added support for custom center of mass in 2D -Calculated center of mass from shapes in 2D (same as in 3D) -Fixed mass properties calculation with disabled shapes in 2D/3D -Removed first_integration which is not used in 2D and doesn't seem to make a lot of sense (prevents omit_force_integration to work during the first frame) -Support for custom inertia on different axes for RigidBody3D --- doc/classes/PhysicsDirectBodyState2D.xml | 3 +++ doc/classes/PhysicsDirectBodyState3D.xml | 1 + doc/classes/PhysicsServer2D.xml | 22 ++++++++++++++++------ doc/classes/PhysicsServer3D.xml | 25 +++++++++++++++++++------ doc/classes/RigidBody2D.xml | 18 ++++++++++++++++-- doc/classes/RigidBody3D.xml | 17 +++++++++++++++++ 6 files changed, 72 insertions(+), 14 deletions(-) (limited to 'doc/classes') diff --git a/doc/classes/PhysicsDirectBodyState2D.xml b/doc/classes/PhysicsDirectBodyState2D.xml index 4c6adfca32..8698fbec61 100644 --- a/doc/classes/PhysicsDirectBodyState2D.xml +++ b/doc/classes/PhysicsDirectBodyState2D.xml @@ -155,6 +155,9 @@ The body's rotational velocity. + + The body's center of mass. + The inverse of the inertia of the body. diff --git a/doc/classes/PhysicsDirectBodyState3D.xml b/doc/classes/PhysicsDirectBodyState3D.xml index 271668e339..4599f86423 100644 --- a/doc/classes/PhysicsDirectBodyState3D.xml +++ b/doc/classes/PhysicsDirectBodyState3D.xml @@ -157,6 +157,7 @@ The body's rotational velocity. + The body's center of mass. The inverse of the inertia of the body. diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml index c412c7ec59..b3b7fcd956 100644 --- a/doc/classes/PhysicsServer2D.xml +++ b/doc/classes/PhysicsServer2D.xml @@ -373,7 +373,7 @@ - + @@ -449,6 +449,13 @@ Removes a shape from a body. The shape is not deleted, so it can be reused afterwards. + + + + + Restores the default inertia and center of mass based on shapes to cancel any custom values previously set using [method body_set_param]. + + @@ -522,7 +529,7 @@ - + Sets a body parameter. See [enum BodyParameter] for a list of available parameters. @@ -936,16 +943,19 @@ Constant to set/get a body's inertia. - + + Constant to set/get a body's center of mass. + + Constant to set/get a body's gravity multiplier. - + 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. diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml index 46cde02f2c..2fbe84b8b1 100644 --- a/doc/classes/PhysicsServer3D.xml +++ b/doc/classes/PhysicsServer3D.xml @@ -347,7 +347,7 @@ - + @@ -430,6 +430,13 @@ Removes a shape from a body. The shape is not deleted, so it can be reused afterwards. + + + + + Restores the default inertia and center of mass based on shapes to cancel any custom values previously set using [method body_set_param]. + + @@ -511,7 +518,7 @@ - + Sets a body parameter. A list of available parameters is on the [enum BodyParameter] constants. @@ -1282,16 +1289,22 @@ Constant to set/get a body's mass. - + + Constant to set/get a body's inertia. + + + Constant to set/get a body's center of mass. + + Constant to set/get a body's gravity multiplier. - + 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. diff --git a/doc/classes/RigidBody2D.xml b/doc/classes/RigidBody2D.xml index 40b5a706c7..0702955495 100644 --- a/doc/classes/RigidBody2D.xml +++ b/doc/classes/RigidBody2D.xml @@ -99,6 +99,13 @@ If [code]true[/code], the body can enter sleep mode when there is no movement. See [member sleeping]. + + The body's custom center of mass, relative to the body's origin position, when [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_CUSTOM]. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration. + When [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_AUTO] (default value), the center of mass is automatically computed. + + + Defines the way the body's center of mass is set. See [enum CenterOfMassMode] for possible values. + If [code]true[/code], the body will emit signals when it collides with another RigidBody2D. See also [member contacts_reported]. @@ -116,8 +123,9 @@ Multiplies the gravity applied to the body. The body's gravity is calculated from the [b]Default Gravity[/b] value in [b]Project > Project Settings > Physics > 2d[/b] and/or any additional gravity vector applied by [Area2D]s. - - 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 function allows you to set a custom value. Set 0 inertia to return to automatically computing it. + + 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]. @@ -202,6 +210,12 @@ Kinematic body mode. The body behaves like a [AnimatableBody2D], and must be moved by code. + + In this mode, the body's center of mass is calculated automatically based on its shapes. + + + In this mode, the body's center of mass is set through [member center_of_mass]. Defaults to the body's origin position. + 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/RigidBody3D.xml b/doc/classes/RigidBody3D.xml index 25fb1edde9..1be35b0576 100644 --- a/doc/classes/RigidBody3D.xml +++ b/doc/classes/RigidBody3D.xml @@ -102,6 +102,13 @@ If [code]true[/code], the body can enter sleep mode when there is no movement. See [member sleeping]. + + The body's custom center of mass, relative to the body's origin position, when [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_CUSTOM]. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration. + When [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_AUTO] (default value), the center of mass is automatically computed. + + + Defines the way the body's center of mass is set. See [enum CenterOfMassMode] for possible values. + If [code]true[/code], the RigidBody3D will emit signals when it collides with another RigidBody3D. See also [member contacts_reported]. @@ -119,6 +126,10 @@ This is multiplied by the global 3D gravity setting found in [b]Project > Project Settings > Physics > 3d[/b] to produce RigidBody3D's gravity. For example, a value of 1 will be normal gravity, 2 will apply double gravity, and 0.5 will apply half gravity to this object. + + 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. See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping. @@ -204,5 +215,11 @@ Kinematic body mode. The body behaves like a [AnimatableBody3D], and can only move by user code. + + In this mode, the body's center of mass is calculated automatically based on its shapes. + + + In this mode, the body's center of mass is set through [member center_of_mass]. Defaults to the body's origin position. + -- cgit v1.2.3