Odd Mechanim Issue - send help!

Hello all,

I think this is the right place for this, if not let me know!

I am following a tutorial on Pluralsight (https://www.pluralsight.com/courses/unity-multiplayer-game-dev-node-2454) and was unable to find the exact model he is using (the bear), but was able to find the same animation pack and used a model from that asset pack.

The issue I am having is that sometimes my click to move works and animates correctly, but sometimes it spazzes out and my character simply runs in circles (and when networked when this happens it causes the other players to also freak out and run in circles, which can sometimes be stopped by setting a new point but only stops the local player).

I have been unable through google to find a solution. Unchecking “Apply Root Motion” on the animator “fixes” the issue but makes the movement slow and choppy. There seems to be a direct correlation to Apply Root Motion and this issue but I cannot find a fix for the life of me. Sometimes the character moves fine, sometimes it freaks out and wont go from running to idle.

Navigation to my knowledge is baked properly. This issue occurs locally when nothing is being sent over the net, so I am fairly sure it has nothing to do with my net code. Idle and Running are the same, just with different names and inverse Transitions. The issue seems to be the transition from run to idle, idle to run works fine.

I am fairly new to Unity and don’t have as good as a grasp on animation and how it works as I would like, so maybe this is something simple? My current working theory is it has something to do with the ray-cast trying to send the player to a point that it can’t for some reason get to so it runs around the point trying to stop there…

Below are the scripts attached to my game world:

This is attached to the main camera:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ScreenClicker : MonoBehaviour {
    // Use this for initialization
    Camera mc; //main camera
 
	void Start () {
        mc = GetComponent<Camera>();
    }
	
	// Update is called once per frame
	void Update () {
	    if (Input.GetButtonDown("Fire2")) {
            Clicked();
        }	
	}
    void Clicked() {
        Ray ray = mc.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit = new RaycastHit();
        if (Physics.Raycast(ray, out hit)) { 
            ClickMove clickMove = hit.collider.gameObject.GetComponent<ClickMove>();
            clickMove.OnClick(hit.point);
        }
    }
}

This to the ground:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ClickMove : MonoBehaviour {
 
    public GameObject player;
	
	// Update is called once per frame
	public void OnClick (Vector3 position) {
        var navPos = player.GetComponent<NavigatePosition>();
        var netMove = player.GetComponent<NetworkMove>();
 
        navPos.NaviagteTo(position);
        netMove.OnMove(position); // send position to network
	}
}

And this to the player:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
 
public class NavigatePosition : MonoBehaviour {
 
    NavMeshAgent agent;
 
	void Start () {
        agent = GetComponent<NavMeshAgent>();
	}
 
	public void NaviagteTo(Vector3 position) {
        agent.SetDestination(position);
    }
 
    private void Update() {
        GetComponent<Animator>().SetFloat("Distance", agent.remainingDistance);
    }
 
}

I have posted for help on the Unity Forums and contacted the Author but have not gotten any answers, hoping the community here might provide better luck :slight_smile:

Thanks :slight_smile:

player_settings

Solved:

This issue had nothing to do with my Contoller, it was an issue with the Angular Speed and Stopping Distance on the Nav Mesh Agent being too low. If you run into an issue where either your Nav Mesh Agent overshoots your destination or turns in circles once getting there check those settings. See https://forum.unity.com/threads/navmeshagent-rotates-on-the-spot-at-its-destination-instead-of-stopping.499391/.

Cheers :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms