0 votes

Does anyone know how to use "linearinterpolation" 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 "linearinterpolate": https://docs.godotengine.org/en/3.1/tutorials/math/interpolation.html

Can somebody help me, please?

in Engine by (80 points)

1 Answer

+2 votes

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)
        return value
by (3,247 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.