How can I set agent's speed on off mesh link? I want it to look like a jump, but now it looks like it was in slow motion.


You can have an Update or FixedUpdate function check when the agent is on an off-mesh link, and modify its speed in response, as shown here:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class LinkSpeedScript : MonoBehaviour

    public NavMeshAgent agent;
    public bool linking;
    public float origSpeed;

    // just change linkspeed to alter off mesh link traverse speed;
    public float linkSpeed;

    void Start()
        origSpeed = agent.speed;
        linking = false;        

    void FixedUpdate()
        if (agent.isOnOffMeshLink && linking == false)
            linking = true;
            agent.speed = agent.speed * linkSpeed;
        else if (agent.isOnNavMesh && linking == true)
            linking = false;
            agent.velocity = Vector3.zero;
            agent.speed = origSpeed;

This seems to work with my NavMeshAgent settings.


This unity forum post suggests handling the traversing yourself.

if(agent.isOnOffMeshLink && !MoveAcrossNavMeshesStarted){

IEnumerator MoveAcrossNavMeshLink()
        OffMeshLinkData data = agent.currentOffMeshLinkData;
        agent.updateRotation = false;

        Vector3 startPos = agent.transform.position;
        Vector3 endPos = data.endPos + Vector3.up * agent.baseOffset;
        float duration = (endPos-startPos).magnitude/agent.Velocity.magnitude;
        float t = 0.0f;
        float tStep = 1.0f/duration;
            transform.position = Vector3.Lerp(startPos,endPos,t);
            agent.destination = transform.position;
            yield return null;
        transform.position = endPos;
        agent.updateRotation = true;
        MoveAcrossNavMeshesStarted= false;


To make it look like a jump, you could

  1. lerp between the two positions and play a jump animation on a child node of the hierarchy
  2. calculate the y-position yourself, e.g.
    s = 0,5 · a · t2 + vo · t + s0
    with vo being the initial velocity and s0 being the inital position. Use this formula for y.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.