Skip to content

Commit 1cfb3ee

Browse files
committed
Small bugfix in 3D platformer
Gravity vector is zero in the first few frames, leading to errors in follow-up calculations expecting a normalized vector. Fixed by assigning a default gravity in case those cases.
1 parent 39590fa commit 1cfb3ee

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

3d/platformer/enemy.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func _integrate_forces(state):
1919
var delta = state.get_step()
2020
var lv = state.get_linear_velocity()
2121
var g = state.get_total_gravity()
22+
# get_total_gravity returns zero for the first few frames, leading to errors
23+
if g == Vector3.ZERO: g = Vector3 (0, -9.8, 0)
2224

2325
lv += g * delta # Apply gravity
2426
var up = -g.normalized()

3d/platformer/player.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func _physics_process(delta):
135135
else:
136136
anim = ANIM_AIR_DOWN
137137

138-
var hs
138+
# var hs
139139
if dir.length() > 0.1:
140140
hv += target_dir * (accel * 0.2) * delta
141141
if (hv.length() > max_speed):

3d/platformer/stage.scn

3 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)