small update to character controller for hard gravity
This commit is contained in:
1 parent
19b2d654d6
commit
3a128eb87d
3 files changed
+23
-4
No files matched your search
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user