Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void FixedUpdate ()
- {
- //Movement
- float xPos = Input.GetAxisRaw("Horizontal");
- float zPos = Input.GetAxisRaw("Vertical");
- Vector3 xMov = Camera.main.transform.right * xPos;
- Vector3 zMov = Camera.main.transform.forward * zPos;
- Vector3 velocity = (xMov + zMov).normalized * speed;
- if (velocity != Vector3.zero)
- {
- rb.MovePosition(rb.position + velocity * Time.deltaTime);
- anim["Idle"].wrapMode = WrapMode.Once;
- anim.PlayQueued("Nothing");
- anim.Stop("Nothing");
- } else
- {
- anim["Idle"].wrapMode = WrapMode.Default;
- StartCoroutine(delayIdle());
- }
- IEnumerator delayIdle ()
- {
- yield return new WaitForSeconds(1.5f);
- if (velocity == Vector3.zero)
- {
- anim.Play("Idle");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment