private void PerformSmoothPlayerMovement() { //this method will smooth the player when is been pushed or moving float newX = Mathf.Lerp(rigidBody2D.velocity.x, 0f, CXMathFunctions.Map(moveDampingSpeed, 0f, 100f, 0f, 1f)); rigidBody2D.velocity = new Vector2(newX, rigidBody2D.velocity.y); }
private void PerformFloatToPlayerBehavior() { //this method will perform that this thing will float to the player if (CheckIfPlayerInRadius() && CheckIfPlayerIsNotFull()) { PerformMoveToPlayer(); } else if (!CXMathFunctions.CheckFloatInRange(rigidBody2D.velocity.x, -.5f, .5f)) { float newVelocityX = Mathf.Lerp(rigidBody2D.velocity.x, 0, CXMathFunctions.Map(itemDampSpeed, 0f, 100f, 0f, 1f)); Vector2 newVelocity = new Vector2(newVelocityX, rigidBody2D.velocity.y); rigidBody2D.velocity = newVelocity; } }
private void PerformCameraZoomBehaviour() { bool pressed = false; //this method will perform the camera to zoom if (Input.GetKey(KeyCode.Equals)) { //then zoom in thisCamera.orthographicSize -= currentZoomSpeed * Time.deltaTime; pressed = true; } if (Input.GetKey(KeyCode.Minus)) { //then zoom out thisCamera.orthographicSize += currentZoomSpeed * Time.deltaTime; pressed = true; } //clamp in thisCamera.orthographicSize = Mathf.Clamp(thisCamera.orthographicSize, cameraZoom_min, cameraZoom_max); if (pressed) { StopAllCoroutines(); cameraZoomValueDisplayText.enabled = true; cameraZoomValueDisplayText.color = Color.white; cameraZoomValueDisplayText.text = CXMathFunctions.Map(thisCamera.orthographicSize, cameraZoom_min, cameraZoom_max, 0f, 100f).ToString("0") + "%"; currentZoomSpeed += zoomSpeedAddingSpeed * Time.deltaTime; currentZoomSpeed = Mathf.Clamp(currentZoomSpeed, zoomSpeed_min, zoomSpeed_max); } else { StopAllCoroutines(); StartCoroutine(TextDissapear(2f)); currentZoomSpeed = zoomSpeed_min; } }