TeHArGiS10

Untitled

Aug 12th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. void FixedUpdate ()
  2. {
  3. //Movement
  4. float xPos = Input.GetAxisRaw("Horizontal");
  5. float zPos = Input.GetAxisRaw("Vertical");
  6.  
  7. Vector3 xMov = Camera.main.transform.right * xPos;
  8. Vector3 zMov = Camera.main.transform.forward * zPos;
  9.  
  10. Vector3 velocity = (xMov + zMov).normalized * speed;
  11.  
  12. if (velocity != Vector3.zero)
  13. {
  14. rb.MovePosition(rb.position + velocity * Time.deltaTime);
  15.  
  16. anim["Idle"].wrapMode = WrapMode.Once;
  17. anim.PlayQueued("Nothing");
  18. anim.Stop("Nothing");
  19. } else
  20. {
  21. anim["Idle"].wrapMode = WrapMode.Default;
  22. StartCoroutine(delayIdle());
  23. }
  24.  
  25. IEnumerator delayIdle ()
  26. {
  27. yield return new WaitForSeconds(1.5f);
  28.  
  29. if (velocity == Vector3.zero)
  30. {
  31. anim.Play("Idle");
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment