4.4 Godot Version
Hello, I created code that adjusts an AudioStreamPlayer3D’s pitch_scale according to the player’s speed using _process(delta). The code works perfectly as intended, but everytime I try to test it out in debug I get spammed with an error message I do not understand but the code works perfectly as intended.
The error is: _process(): Condition "p_pitch_scale <= 0.0" is true.
My code is:
@onready var slide = $slide
func _process(delta):
slide.pitch_scale = Plrstats.player_speed * 0.1
is Plrstats.player_speed
ever 0
I think @paintsimmon is probably on the right track. If player_speed
ever goes negative (even just a tiny little bit, like -0.0000001) hilarity may ensue. The easy fix is clampf()
:
slide.pitch_scale = clampf(Plrstats.player_speed * 0.1, 0.0, SOME_MAX_VALUE)
1 Like
thanks for the help and i did resolve it with this:
var scale_range
@onready var slide = $slide
func _physics_process(delta):
current_speed = velocity.length()
if current_speed > 0:
scale_range = current_speed * 0.1
slide.set_pitch_scale(scale_range)
slide.pitch_scale = clampf(slide.pitch_scale, 0.2, 4)
else:
slide.stop()
It also worked in _process(delta) as well.
2 Likes