Pathfinding causing Vector3.Slerp to curve?

So I’m just getting started diving into the A* Pathfinding Project, and I absolutely love it.

One strange behavior I’ve experienced is that when disabling the AIPath script and then moving my character using Vector3.Slerp: there’s a curve in the movement that isn’t present when I disable the AIPath script. The curve isn’t consistent and sometimes arcs a lot wider than others.

Here’s a video showing off what I mean by curving.

I’m temporarily disabling the pathfinder by setting canMove and canSearch to false until the slerping is complete. Is there something that I need to turn off that I’m missing?

Hi

How exactly does your slerping code look?

Heya @aron_granberg , sorry for the delay.

Here’s what I’m doing:

public void Leap()
 {
     startPos = transform.position;
     endPos = transform.position + (transform.forward * leapDistance);
     Leaping = true;
     GetComponent<AIPath>().canMove = false;
     GetComponent<AIPath>().canSearch = false;

  }

private void FixedUpdate()
    {
        if (Leaping)
        {

            // For now we will just lerp, but we'll want to look into jumping up later.
            transform.position = Vector3.Slerp(transform.position, endPos, ((leapDistance / leapDuration) / 2) * Time.fixedDeltaTime);

            if(Vector3.Distance(transform.position, endPos) <= .5f)
            {
                Leaping = false;
                GetComponent<AIPath>().canMove = true;
                GetComponent<AIPath>().canSearch = true;
            }
        }
    }

Might be that I’m overlooking something simple, but afaik it should be working fine.

Hi
With that code the curving behaviour is expected. Perhaps you want to use lerp instead of slerp? Lerp will move the objects in a straight line.

1 Like

Haha yep that was it, mixed the two up in my mind. Rookie mistake- thanks.