small update to character controller for hard gravity

This commit is contained in:
OddlyTimbot committed 2025-02-24 17:07:24 -05:00
1 parent 19b2d654d6
commit 3a128eb87d
3 files changed
+23 -4

No files matched your search

@@ -4,7 +4,7 @@ extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -500.0
const PUSH_FORCE = 50
var hard_gravity := 1
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@@ -12,9 +12,15 @@ var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta):
# Gravity applies any time character is not on floor
if not is_on_floor():
velocity.y += gravity * delta
# Try modifying the properties for a unique game feel
# In this case, once gravity overcomes the jump a multiplier is
# applied that speeds up falling.
if velocity.y > 0:
hard_gravity*=1.8
velocity.y += gravity * hard_gravity * delta
#eventually, gravity overcomes jump velocity (see below)
else:
hard_gravity = 1
# Only allow jump from starting on floor
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY