Non Fluid Character Movement

Hi guys…

I’m having some issues in what referes with my character movement… The question is, im using 1st navemesh to move the character if im in image location and try to go point A everythings goes well if i dont try back before it reachs the A point. If i click to go point A and before it takes it i click to point B instead of just turn and move the player describes that kinda of curve and before it curve it runs a bit forward first and then it goes fine at B point. Wt i would like to know is if this is a scripting problem or since im using a squeleton asset could be the animation that come with problem but i really dont thing thats an animation problem. If someone can help i will appreciate…

I will post the script and the image.

using UnityEngine;

[RequireComponent(typeof(NavMeshAgent))]

public class Move : MonoBehaviour
{
    public AnimationClip idle;
    public AnimationClip run;

    public enum MouseButtonType {Left, Right, Middle};
    public MouseButtonType mouseButton = MouseButtonType.Left;

    public Transform myTransform;
    private NavMeshAgent navMeshAgent;
    private Animation anim;

    void Awake()
    {
        myTransform = transform;
        anim = GetComponent<Animation> ();
        navMeshAgent = GetComponent<NavMeshAgent> ();
    }

    // Update is called once per frame
    void Update ()
    {
        if (navMeshAgent.remainingDistance < 0.5f)
        {
            if (idle != null && anim != null) anim.CrossFade (idle.name);       
        } else
        {
            if(run != null && anim != null) anim.CrossFade (run.name);   
        }

        //Move player if left mouse button is clicked
        if (Input.GetMouseButtonDown ((int)mouseButton) && GUIUtility.hotControl == 0)
        {
            Plane playerPlane = new Plane (Vector3.up, myTransform.position);
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            float hitdist = 0.0f;

            if (playerPlane.Raycast (ray, out hitdist))
            {
                navMeshAgent.SetDestination (ray.GetPoint (hitdist));
            }
        }

        //Move player if the mouse button is held down
        else if (Input.GetMouseButton ((int)mouseButton) && GUIUtility.hotControl == 0)
        {
            Plane playerPlane = new Plane (Vector3.up, myTransform.position);   
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            float hitdist = 0.0f;

            if (playerPlane.Raycast (ray, out hitdist))
            {
                navMeshAgent.SetDestination (ray.GetPoint (hitdist));
            }
        }
    }
}

Bump… Anyone plz?

Hey, i heaven’t done anything with NavMeshAgent but have you tried to change the “Angular Speed” in your NavMeshAgent Component ?

In the manuel they say: “Angular Speed - Maximum speed of rotation (degrees per second).”
http://docs.unity3d.com/Manual/class-NavMeshAgent.html

-lg Alex :wink:

Hi m8. Yap i try and goes a bit better but not perfect… it just keep doing the curve a bit instead of just turn and run back… For me the problem only could be with NavMesh or Character Animations but i believe thats a NavMesh Problem… Appreciate

How about that?
Call that when you get a new Position by Clicking the Mouse (Overwrite your old speed system!!)

Sytax not Tested!

void changeSpeed()
{
   float speedMultiplyer = 1.0f - 0.9f * Vector3.Angle (transform.forward, agent.steeringTarget - transform.position) / 180.0f;
   agent.speed = moveSpeed * speedMultiplyer;
}

-lg Alex :wink:

I increase the aceleration in NavMesh and it seems to work now but i will test ur lines :wink: Ty M8

1 Like