diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-05 14:48:31 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-05 14:48:31 +0100 |
commit | acde2a81ffc27680ac08e32f70134dfcd1dd59f0 (patch) | |
tree | 835c737c4cd6aace9630717c423d732c8c00ea91 /modules/mono/editor | |
parent | b4e2a24c1f62088b3f7ce0197afc90832fc25009 (diff) | |
parent | aed5ea946036e6c2c8a0165265bb6b038b3db8cb (diff) | |
download | redot-engine-acde2a81ffc27680ac08e32f70134dfcd1dd59f0.tar.gz |
Merge pull request #84640 from aaronfranke/gravity-get
Expose a method to get gravity for any physics body
Diffstat (limited to 'modules/mono/editor')
-rw-r--r-- | modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs | 9 | ||||
-rw-r--r-- | modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs | 9 |
2 files changed, 10 insertions, 8 deletions
diff --git a/modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs b/modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs index 87468fb433..698157c6b4 100644 --- a/modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs +++ b/modules/mono/editor/script_templates/CharacterBody2D/basic_movement.cs @@ -8,20 +8,21 @@ public partial class _CLASS_ : _BASE_ public const float Speed = 300.0f; public const float JumpVelocity = -400.0f; - // Get the gravity from the project settings to be synced with RigidBody nodes. - public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle(); - public override void _PhysicsProcess(double delta) { Vector2 velocity = Velocity; // Add the gravity. if (!IsOnFloor()) - velocity.Y += gravity * (float)delta; + { + velocity += GetGravity() * (float)delta; + } // Handle Jump. if (Input.IsActionJustPressed("ui_accept") && IsOnFloor()) + { velocity.Y = JumpVelocity; + } // Get the input direction and handle the movement/deceleration. // As good practice, you should replace UI actions with custom gameplay actions. diff --git a/modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs b/modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs index ddeb9d7e00..30dabd31d9 100644 --- a/modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs +++ b/modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs @@ -8,20 +8,21 @@ public partial class _CLASS_ : _BASE_ public const float Speed = 5.0f; public const float JumpVelocity = 4.5f; - // Get the gravity from the project settings to be synced with RigidBody nodes. - public float gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle(); - public override void _PhysicsProcess(double delta) { Vector3 velocity = Velocity; // Add the gravity. if (!IsOnFloor()) - velocity.Y -= gravity * (float)delta; + { + velocity += GetGravity() * (float)delta; + } // Handle Jump. if (Input.IsActionJustPressed("ui_accept") && IsOnFloor()) + { velocity.Y = JumpVelocity; + } // Get the input direction and handle the movement/deceleration. // As good practice, you should replace UI actions with custom gameplay actions. |