void FixedUpdate() { //if (transform.position.y < -10) //ResetToSave(); bool onGround = Physics2D.Raycast(new Vector2(PlayerRB.position.x + 0.25F * transform.localScale.x, PlayerRB.position.y + 0.74F * transform.localScale.y), Vector2.down, 0.05F); if (onGround != this.onGround) { this.onGround = onGround; if (!onGround) { DirtParticles.Stop(false, ParticleSystemStopBehavior.StopEmitting); } else { DirtParticles.Play(); } DirtParticles.Emit(10); } if (onGround) { vel.y = 0; lastOnGround = Time.time; } if (Mathf.Abs(movementVal) > 0.1F) { movement = Mathf.Lerp(movement, movementVal, movementSmoothAcc * Time.fixedDeltaTime); } else { movement = movementVal; } vel.x = movement * speed; if (movement >= 0.1F && !isTurnedRight) { transform.rotation = Quaternion.Euler(0f, 0f, 0f); Turn(); } if (movement <= -0.1F && isTurnedRight) { transform.rotation = Quaternion.Euler(0f, 180f, 0f); Turn(); } stepSound.volume = Mathf.Abs(movement) * (onGround ? 0.5F : 0); float jump = 0; if (Time.time - lastOnGround < coyote && jumped) { lastOnGround = -100; jump = jumpForce; PlayerAnim.SetTrigger("Jump"); DirtParticles.Emit(10); jumpSound.Play(); } jumped = false; vel += new Vector2(0, jump); vel += Physics2D.gravity * Time.fixedDeltaTime; if (vel.y < 0) { vel += Physics2D.gravity * 0.2F * Time.fixedDeltaTime; } PlayerRB.velocity = vel; PlayerAnim.SetBool("Air", !onGround); PlayerAnim.SetFloat("Movement", Mathf.Max(0.05F, Mathf.Abs(movement * speed))); }