Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Slerp does the same as lerp

Discussion in 'Scripting' started by unity_STQDhyd7LkBPcg, Jul 15, 2018.

  1. unity_STQDhyd7LkBPcg

    unity_STQDhyd7LkBPcg

    Joined:
    Jul 15, 2018
    Posts:
    1
    Hello!

    for a project, i have to show the difference between Lerp & slerp.
    I know what each does and how is has to look, i wrote a script for each method, but for some reason, vector3.slerp does the same as vector3.lerp and i can't find my error.

    Can't upload Pictures, so here is my code for lerp:
    ________________________________________

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class lerp : MonoBehaviour {
    public GameObject igel;

    private Vector3 startPos;

    private Vector3 endPos;
    public float t = 0.00f;
    void Start() {
    startPos = new Vector3(-150f, 1.6f, 734f);
    endPos = new Vector3(150f, 1.6f, 734f);
    }
    void Update() {
    if(Input.GetKeyDown (KeyCode.A)) {
    igel.transform.position = Vector3.Lerp(endPos, startPos, t);
    }
    if(Input.GetKeyDown (KeyCode.S)) {
    igel.transform.position = Vector3.Lerp(startPos, endPos, t);
    }
    }
    }

    ________________________________________

    and slerp:

    ________________________________________

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class slerp : MonoBehaviour {
    public GameObject igel;

    private Vector3 startPos;

    private Vector3 endPos;
    public float t = 0.00f;
    void Start() {
    startPos = new Vector3(-150f, 1.6f, 734f);
    endPos = new Vector3(150f, 1.6f, 734f);
    }
    void Update() {
    if(Input.GetKeyDown (KeyCode.Q)) {
    igel.transform.position = Vector3.Slerp(endPos, startPos, t);
    }
    if(Input.GetKeyDown (KeyCode.W)) {
    igel.transform.position = Vector3.Slerp(startPos, endPos, t);
    }
    }
    }
     
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,479
    I never used it, for a position and use lerp and easing function for position.

    Where you will see the use of slerp is for a vector or quaternion rotation.

    So use a quaternion or give it 2 normalized vectors that are facing different directions.
     
  3. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,130
    Read the description of V3.Slerp again (it mentions the difference between it and Lerp) and maybe try it with two points more opposite each other from (0,0,0.) Lerp will always give a straight line. Slerp will give a curve -- it spins you around (0,0,0). If the points are far from there but far apart, you get a only very, very small curve, which no-one will notice.
     
unityunity