meat_madness_redux/godot/util.gd

34 lines
884 B
GDScript3
Raw Normal View History

2022-11-27 13:31:09 -07:00
extends Node
onready var player = $"/root".find_node("Player", true, false)
func vec3_componentwise_clamp(vec: Vector3, lower: float, upper: float) -> Vector3:
return Vector3(
clamp(vec.x, lower, upper),
clamp(vec.y, lower, upper),
clamp(vec.z, lower, upper)
)
func vec2_xz_to_vec3(xz: Vector2, y: float = 0.0) -> Vector3:
return Vector3(xz.x, y, xz.y)
func vec3_xz(vec: Vector3) -> Vector2:
return Vector2(vec.x, vec.z)
func deactivate_node(node: Node):
node.set_process(false)
node.set_physics_process(false)
node.set_process_input(false)
func activate_node(node: Node):
node.set_process(true)
node.set_physics_process(true)
node.set_process_input(true)
2022-12-11 12:23:58 -07:00
func clamped_lerp(src: float, dest: float, weight: float, close_enough: float):
weight = clamp(weight, 0.0, 1.0)
var v = lerp(src, dest, weight)
if abs(dest - v) < close_enough:
return dest
return v