void Update() { grounded = characterController.isGrounded; // movement if (speed > 0 || !grounded) { if (moveDirection.sqrMagnitude > 0.1f) { body.transform.rotation = Quaternion.RotateTowards(body.transform.rotation, Quaternion.LookRotation(moveDirection.normalized, Vector3.up), Time.deltaTime * 360 * 2); } moveDirection *= speed; if (!grounded) { moveDirection.y -= gravity * Time.deltaTime; } else { moveDirection.y = 0; } characterController.Move(moveDirection * Time.deltaTime); if (aimDirection != Vector3.zero) { turret.transform.LookAt(turret.transform.position + aimDirection); } } if (canPickObj && hoveredObject && Input.GetKeyDown(KeyCode.Space)) { if (hoveredObject.toPick.GetType() == typeof(Weapon)) { equipement.SetWeapon(((Weapon)hoveredObject.toPick).type); } else if (hoveredObject.toPick.GetType() == typeof(SecondaryWeapon)) { equipement.SetSecondaryWeapon(((SecondaryWeapon)hoveredObject.toPick).type); } else if (hoveredObject.toPick.GetType() == typeof(Passive)) { equipement.SetPassive(((Passive)hoveredObject.toPick).type); } hoveredObject.GotPicked(); } float alpha = 0.7f; smoothedVelocity = (1.0f - alpha) * smoothedVelocity + alpha * new Vector2(characterController.velocity.x, characterController.velocity.z); moving = smoothedVelocity.magnitude > 0.9f; }