Godot Version
4.2.2
Question
I’ve just started working with Godot, but when I try to increase the player’s speed, the sprite starts to jitter. This only happens when the player begins to run.
func _physics_process(delta):
if manager_scene.menuActive:
return
if entering_trigger:
transition(delta)
elif playerstate == State.turning:
return
elif playerstate == State.parado:
inputPlayer()
elif playerstate == State.walking or playerstate == State.running:
move(delta)
else:
playerstate = State.parado
func updateAnimation():
var blendPosition = Vector2.ZERO
match facingstate:
Facing.left:
blendPosition = Vector2(-1, 0)
Facing.right:
blendPosition = Vector2(1, 0)
Facing.up:
blendPosition = Vector2(0, -1)
Facing.down:
blendPosition = Vector2(0, 1)
match playerstate:
State.parado:
anitree.set("parameters/Parado/blend_position", blendPosition)
anistate.travel("Parado")
State.walking:
anitree.set("parameters/Walk/blend_position", blendPosition)
anistate.travel("Walk")
State.turning:
anitree.set("parameters/Turn/blend_position", blendPosition)
anistate.travel("Turn")
State.running:
anitree.set("parameters/Run/blend_position", blendPosition)
anistate.travel("Run")
_:
anistate.travel("Parado")
func move(delta):
var nextstep:Vector2 = dir * TileSize / 2
ray.target_position = nextstep
ray.force_raycast_update()
ledge_ray.target_position = nextstep
ledge_ray.force_raycast_update()
trigger_ray.target_position = nextstep
trigger_ray.force_raycast_update()
updateAnimation()
if trigger_ray.is_colliding() or entering_trigger:
if !entering_trigger:
emit_signal("Player_entering_trigger")
entering_trigger = true
hasFadedtoBlack = false
hasFadedtoNormal = false
elif (ledge_ray.is_colliding() && facingstate == Facing.down) or jumping_overledge:
nextTile += jump_spd * delta
if nextTile >= 2.0:
position = posinicial + (2 * TileSize * dir)
nextTile = 0.0
playerstate = State.parado
jumping_overledge = false
shadow.visible = false
sprite.position = Vector2(8, -2)
else:
shadow.visible = true
jumping_overledge = true
position = posinicial + (TileSize * dir * nextTile * 2 / 2)
var input = dir.y * TileSize * nextTile / 2
sprite.position.y = (- 4 - 1.2 * input + 0.087 * pow(input, 2))
elif !ray.is_colliding():
if playerstate == State.running:
nextTile += run_spd * delta
print(position)
else:
nextTile += spd * delta
if nextTile >= 1.0:
position = posinicial + (TileSize * dir)
nextTile = 0.0
playerstate = State.parado
else:
position = posinicial + (TileSize * dir * nextTile)
else:
playerstate = State.parado
nextTile = 0.0
posinicial = position
physics ticks per second: 60
I tried increasing that value ridiculously to see what would happen, but the problem persisted.