Open Shadowblitz16 opened 5 years ago
It would be nice to have a shorter, to the point script or project. The code pasted does a lot more than range_lerp
, and we don't have the values assigned to your export variables to try it (nor your scene).
I can try to get a better script
ok here is a more compact script.. attach it to a area2D
extends Area2D
var move_velocity = Vector2(0,0)
const move_fric = 2
const move_speed = 2
const move_accelF = 2
const move_decelB = 2
func _process(delta):
var move_dir = Vector2(0,-1).rotated(rotation)
var slow_dir = Vector2(0, 0)
move_velocity = real_lerp(move_velocity, slow_dir, move_fric)
if (Input.is_action_pressed("ui_up" )): move_velocity = real_lerp(move_velocity, move_dir, move_accelF)
if (Input.is_action_pressed("ui_down" )): move_velocity = real_lerp(move_velocity, slow_dir, move_decelB)
print("{"+str(move_velocity.x)+", "+str(move_velocity.y)+"}")
func real_lerp(min_value, max_value, by):
if (typeof(min_value) == TYPE_VECTOR2 && typeof(max_value) == TYPE_VECTOR2):
var value_x = real_lerp(min_value.x, min_value.x, by);
var value_y = real_lerp(max_value.y, max_value.y, by);
return Vector2(value_x, value_y);
elif (typeof(min_value) == TYPE_VECTOR2 && typeof(max_value) == TYPE_REAL):
var value_x = real_lerp(min_value.x, max_value, by);
var value_y = real_lerp(min_value.y, max_value, by);
return Vector2(value_x, value_y);
else:
var value = range_lerp(by, 0, max_value-min_value, min_value, max_value);
return value;
Value from range_lerp is undefined if range size == 0 (istart == istop or ostart == ostop) (https://github.com/godotengine/godot/pull/10225#issuecomment-321735458)
var value = range_lerp(by, 0, max_value-min_value, min_value, max_value);
Converting to constants (for first iteration) gives:
var value = range_lerp(2, 0, 0-0, 0, 0);
I guess this simply needs to be documented.
Godot version: 3.0.6 Windows 7 Home 64 bit
it seems like I am getting odd values out of range_lerp that prints as
-1.#IND
I feel that this is because I am passing unordered min and max and passing and values below min and max. however these things should not matter and passing values to lerp functions should be unclamped and scale depending on the order of the min and max values and their ranges.
here is a sample script on the issue.