Topic was automatically imported from the old Question2Answer platform.
Asked By
Star Frog
Does anyone know how to use “linear_interpolation” in 3D? I would make a weapon swaying, like PlanetSide2 or Battlefield. I think I had tried everything, but without some success. Here I’ve found the description of “linear_interpolate”: Interpolation — Godot Engine (3.1) documentation in English
For something to sway you need to lerp using an amount that ping-pongs similar to Unity’s Mathf.PingPong.
Here’s a script that has a custom ping pong method.
export var number : float
export var pingpong_amount : float
func _process(delta):
translation.lerp(start, end, ping_pong(number, pingpong_amount))
number += delta
func ping_pong(number, pingpong):
var length = 2*pingpong
var value = number
while value > length:
value -= length
if value > pingpong:
return pingpong-(value-pingpong)
else:
return value