summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2023-11-08 16:56:19 -0600
committerAaron Franke <arnfranke@yahoo.com>2024-01-30 23:57:38 -0600
commitaed5ea946036e6c2c8a0165265bb6b038b3db8cb (patch)
tree97c2e825533617a2c3b12a45e6c5a09e06886b0b /modules/mono/editor
parent313f623b9d102cc8c411ae7cab9518f98c2f87f2 (diff)
downloadredot-engine-aed5ea946036e6c2c8a0165265bb6b038b3db8cb.tar.gz
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.cs9
-rw-r--r--modules/mono/editor/script_templates/CharacterBody3D/basic_movement.cs9
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.