small update to character controller for hard gravity

This commit is contained in:
OddlyTimbot 2025-02-24 17:07:24 -05:00
parent 19b2d654d6
commit 3a128eb87d
3 changed files with 23 additions and 4 deletions

View File

@ -54,7 +54,7 @@ position = Vector2(-1.5, 0)
shape = SubResource("RectangleShape2D_cq7kj")
[node name="groundblock3" type="StaticBody2D" parent="level"]
position = Vector2(404, 345)
position = Vector2(378, 279)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="level/groundblock3"]

View File

@ -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

View File

@ -35,5 +35,18 @@ Create a trigger via Area2D. Create in a way that it can be used to trigger mult
Make a playable character that uses the CharacterBody2D template.
## Architecture
It is not too soon to start thinking about how to organize a game! Through this project, we will be creating a project architecture that is good for small to mid-sized games.
Creating a predictable architecture is about making a 'separation of concerns' in your code. Our architecture will be broken up into three concerns.
1. Game Controller
This tier keeps track of all data and logic rules.
2. SceneManager
The scene manager keeps track of everything that is on the screen at any given time.
3. View
This tier is where all of our game assets (in Godot "scenes" and "nodes") are kept.
-----------------