# Wall-crawling around corners

I’ve gotten NavMeshes onto my walls and have creepy crawler spiders on them. I have 5 nav meshes (4 walls, floor, no ceiling) each baked manually with separate NavMeshSurfaces, each rotated.

The issue is corners. I have used the nav link component to link the different meshes. The spiders traverse but there’s one issue. Their rotation instantly snaps to the “new normal”. I want interpolation while they go over the link to smooth this rotation and make it look natural.

I’ve adapted this coroutine from OffMeshLinkMoveMethod to try and add Slerp. The problem variable is EndRot, I think. I cannot figure it out for the life of me.

If we have the local rotation and current position, and we have the endPos, and we can assume there is something solid beneath the spider at both points, and we know the corner is a right angle, surely we can calculate the final rotation in order to Slerp into it. Right?

``````    IEnumerator Curve(NavMeshAgent agent, float duration)
{
Vector3 startPos = agent.transform.position;
Vector3 endPos = data.endPos + Vector3.up * agent.baseOffset;

Vector3 direction = (endPos - startPos).normalized;

Quaternion startRot = agent.transform.rotation;

//This here is not quite right
Quaternion endRot = Quaternion.LookRotation(direction);

float normalizedTime = 0.0f;
while (normalizedTime < 1.0f)
{
agent.updateRotation = false;

float yOffset = m_Curve.Evaluate(normalizedTime);
agent.transform.position = Vector3.Lerp(startPos, endPos, normalizedTime) + yOffset * Vector3.up;

agent.transform.rotation = Quaternion.Slerp(startRot, endRot, normalizedTime);

normalizedTime += Time.deltaTime / duration;
yield return null;
}
agent.updateRotation = true;
}
``````

I’ll attempt to better the illustrate the issue. For the last two spiders, their rotation should not snap like that at the end of the jump. It should Slerp via this line.

`agent.transform.rotation = Quaternion.Slerp(startRot, endRot, normalizedTime);`

All transition corners like this are 90 degrees.
Current position, known.
Current rotation, known.
Current up Vector, known.
End position of the transition, known.
Obviously we can assume there is something solid directly beneath the spider at both start and end position.
So the final rotation of the spider is ________ ??

Who out there remembers this day from Math class? I’m so close to finishing this awesome effect, but the final step is slaying me here. Like… rotate a Vector3 along another Vector3 between the start and end position? Take into account the local rotation of the current position to get an up vector, then we know it’s a 90 degree corner… so we… ???

I tried implementing ChatGPT’s solution