void FixedUpdate() { //Debug.Log(transform.rotation); float inputX = Input.GetAxisRaw("Horizontal") > 0 ? 1 : (Input.GetAxisRaw("Horizontal") < 0 ? -1 : 0); float inputZ = Input.GetAxisRaw("Vertical") > 0 ? 1 : (Input.GetAxisRaw("Vertical") < 0 ? -1 : 0); if (inputX != 0 || inputZ != 0) { var cam = Camera.main; var forward = cam.transform.forward; var right = cam.transform.right; forward.y = 0f; right.y = 0f; forward.Normalize(); right.Normalize(); Vector3 desiredMoveDirection = forward * inputZ + right * inputX; transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(desiredMoveDirection), 0.1f); rigidBody.velocity = desiredMoveDirection * Time.fixedDeltaTime * 500; animator.SetFloat("Blend", 1, 0.3f, Time.fixedDeltaTime); if (!soundsPlayer.IsPlaying(0)) { soundsPlayer.Play(0); } } else { rigidBody.velocity = Vector3.zero; animator.SetFloat("Blend", 0, 0.15f, Time.fixedDeltaTime); soundsPlayer.Stop(0); } }
void FixedUpdate() { if (posTarget != null && Vector3.Distance(transform.position, posTarget) > 0.1f) { transform.rotation = rotTarget; Vector3 dir = (posTarget - transform.position).normalized; rigidBody.velocity = dir * Time.fixedDeltaTime * 500; animator.SetFloat("Blend", 1, 0.3f, Time.fixedDeltaTime); if (!soundsPlayer.IsPlaying(0)) { soundsPlayer.Play(0); } } else { rigidBody.velocity = Vector3.zero; animator.SetFloat("Blend", 0, 0.15f, Time.fixedDeltaTime); soundsPlayer.Stop(0); } }