// draw velocity vector //void OnDrawGizmos() //{ // // draw trajectory // if (agent == null || agent.path == null) // return; // var line = this.GetComponent<LineRenderer>(); // if (line == null) // { // line = this.gameObject.AddComponent<LineRenderer>(); // line.material = new Material(Shader.Find("Sprites/Default")) { color = Color.yellow }; // line.startWidth = 0.1f; // line.endWidth = 0.2f; // line.startColor = Color.yellow; // line.endColor = Color.red; // } // var path = agent.path; // line.SetPositions(path.corners); //} void Start() { // Set values agent = GetComponent <NavMeshAgent>(); anim = GetComponentInChildren <Animator>(); interactScript = this.GetComponent <interact>(); lookAtScript = this.GetComponent <lookAt>(); // enable lookAt enableLookAt(0); // Don’t update position automatically agent.updatePosition = false; // start path to first target resetDestination(); // if on a conversation do not move or interact if (interactScript.onConversation) { interactScript.Start(); interactScript.startToConversate(); return; } // if its animated start triggering animations if (interactScript.animated) { interactScript.callTriggerInteraction(); } }
void FixedUpdate() { float horizontal = Input.GetAxisRaw("Horizontal"); float vertical = Input.GetAxisRaw("Vertical"); if (horizontal != 0 || vertical != 0) { animator.SetFloat("LookX", horizontal); animator.SetFloat("LookY", vertical); animator.SetFloat("Speed", Speed); if (Mathf.Abs(horizontal) >= Mathf.Abs(vertical)) { if (horizontal > 0) { look = lookAt.Right; } else { look = lookAt.Left; } } else { if (vertical > 0) { look = lookAt.Up; } else { look = lookAt.Down; } } } else { animator.SetFloat("Speed", 0); } rb.velocity = new Vector2(horizontal, vertical) * Speed; }