// Update is called once per frame private void LateUpdate() { m_CurrentRotation = Vector3.SmoothDamp(m_CurrentRotation, new Vector3(m_Pitch, m_Yaw), ref m_RotationSmoothVelocity, m_RotationSmoothTime); transform.eulerAngles = m_CurrentRotation; transform.position = player.transform.position - transform.forward * m_DistanceFromTarget; }
// Start is called before the first frame update // Update is called once per frame void Update() { //Rotating the camerra around the board to focuse on the current player var currSide = tPlayer.currSpot.GetComponent <WalkableScript>().side; if (currSide == Boardside.Left) { cameraOffset.z = -2; cameraOffset.x = 0; } else if (currSide == Boardside.Bottom) { cameraOffset.z = 0; cameraOffset.x = 2; } else if (currSide == Boardside.Top) { cameraOffset.z = 0; cameraOffset.x = -2; } else if (currSide == Boardside.Right) { cameraOffset.z = 2; cameraOffset.x = 0; } Vector3 dPosition = target.position + cameraOffset; Vector3 sPosition = Vector3.SmoothDamp(transform.position, dPosition, ref velocity, smoothSpeed); transform.position = sPosition; Quaternion dRotation = Quaternion.Euler(25, (int)currSide, 0); transform.rotation = Quaternion.Slerp(transform.rotation, dRotation, Time.deltaTime * smoothSpeed); }
// Update is called once per frame void LateUpdate() { if (!follow) { return; } // Move the mid-point of the camera, and clamp the value to the defined radius. // Assign the position to the cameraMidPoint object. Vector3 midPointPos = playerTransform.position + (Camera.main.ScreenToWorldPoint(Input.mousePosition) - playerTransform.position) / 2; //midPointPos = Vector3.ClampMagnitude(midPointPos, cameraRadius); //print(midPointPos); midPointPos = new Vector3(Mathf.Clamp(midPointPos.x, -5, 5), Mathf.Clamp(midPointPos.y, -5, 5)); cameraMidPoint.position = midPointPos; // --- viewPortSize = (mainCamera.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height)) - mainCamera.ScreenToWorldPoint(Vector2.zero)) * viewPortFactor; distance = cameraMidPoint.position - transform.position; if (Mathf.Abs(distance.x) > viewPortSize.x / 2) { targetPosition.x = cameraMidPoint.position.x - (viewPortSize.x / 2 * Mathf.Sign(distance.x)); } if (Mathf.Abs(distance.y) > viewPortSize.y / 2) { targetPosition.y = cameraMidPoint.position.y - (viewPortSize.y / 2 * Mathf.Sign(distance.y)); } transform.position = Vector3.SmoothDamp(transform.position, targetPosition - new Vector3(0, 0, 10), ref currentVelocity, followDuration, maximumFollowSpeed); }
void FollowPlayerObj() { Vector3 targetPos = player.transform.TransformPoint(new Vector3(0, yOffset, -10)); targetPos = new Vector3(0, targetPos.y, targetPos.z); transform.position = Vector3.SmoothDamp(transform.position, targetPos, ref Velocity, smoothTime); }
void LateUpdate() { /*Vector3 targetPosition = target.TransformPoint(new Vector3(0, 1, -3)); * * transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime); * * transform.LookAt(target);*/ if (RotateAroundTarget) { Quaternion camTurnAngle = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * RotationSpeed, Vector3.up); cameraOffset = camTurnAngle * cameraOffset; } Vector3 newPos = targetTransform.position + cameraOffset; //transform.position = Vector3.Slerp(transform.position, newPos, smoothFactor); transform.position = Vector3.SmoothDamp(transform.position, newPos, ref velocity, smoothTime); if (LookAtTarget || RotateAroundTarget) { transform.LookAt(targetTransform); } }
public void Move(float move, bool jump) { //If the player is in regular gravity if (m_Rigidbody2D.gravityScale >= 3f) { if (mGrounded || m_AirControl) { // Move the character by finding the target velocity Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y); // And then smoothing it out and applying it to the character m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing); } } else if (m_Rigidbody2D.gravityScale == 0.5f) { Vector2 directionVector2 = new Vector2(move, Input.GetAxisRaw("Vertical") * -1) * 5; m_Rigidbody2D.AddForce(directionVector2); } else { Vector2 guideDir = GetDirection(transform.position, guide.transform.position); //only control the player if grounded or airControl is turned on if (planGrounded && Attracted) { Vector2 targetVelocity = guideDir * (2f * Mathf.Abs(move)); m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing); } else if (attracted) { Vector2 targetForce = guideDir * (2f * Mathf.Abs(move)); m_Rigidbody2D.AddForce(targetForce); } } // If the input is moving the player right and the player is facing left... if (move > 0 && !mFacingRight) { // ... flip the player. Flip(); } // Otherwise if the input is moving the player left and the player is facing right... else if (move < 0 && mFacingRight) { // ... flip the player. Flip(); } // If the player should jump... if (mGrounded && jump) { // Add a vertical force to the player. mGrounded = false; m_Rigidbody2D.AddRelativeForce(new Vector2(0f, m_JumpForce)); } }
void Move() { Vector3 centerPoint = GetCenterPoint(); Vector3 newPosition = centerPoint + offset; transform.position = Vector3.SmoothDamp(transform.position, newPosition, ref velocity, smoothTime); }
void SetCameraPosition(int index) { var r = GameManager.instance.cam.velocity; var cameraPosition = Vector3.SmoothDamp(GameManager.instance.cam.transform.position, new Vector3(0, y: index + 9.5f, GameManager.instance.cam.transform.position.z), ref r, source.pitch * Time.deltaTime); GameManager.instance.cam.transform.position = new Vector3(0f, index, GameManager.instance.cam.transform.position.z); }
// Update is called once per frame void Update() { transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime); timeToPhotoLeft = Math.Max(0, timeToPhotoLeft - Time.deltaTime); if (!photoShot && Math.Abs(timeToPhotoLeft) < 0.05) { ShootPhoto(); } }
void SmoothFollow() { Vector3 targetPosition = objectOfFocus.position; targetPosition.x = objectOfFocus.position.x; targetPosition.z = objectOfFocus.position.z + zOffset; targetPosition.y = objectOfFocus.position.y + yOffset; Vector3 currentPosition = Vector3.SmoothDamp(_selfTransform.position, targetPosition, ref velocity, smoothTime); _selfTransform.position = currentPosition; }
public void CreateMoveDirection(Vector2 axis) { var movementSpeed = _alwaysRun || _isRunning ? _runningSpeed : _walkingSpeed; var forward = transform.TransformDirection(Vector3.forward); var right = transform.TransformDirection(Vector3.right); var direction = (right * axis.x + forward * axis.y).normalized * movementSpeed; var moveDirectionY = _moveDirection.y; _moveDirection = Vector3.SmoothDamp(_moveDirection, direction, ref _velocity, _smoothTime); _moveDirection.y = moveDirectionY; }
void Update() { if (!previousIsGrounded && body.IsGrounded) { force = Vector3.down * (Mathf.Abs(previousVelocity.y) * factor); Add(force); if (speedLossRoutine != null) { StopCoroutine(speedLossRoutine); } speedLossRoutine = StartCoroutine(SpeedLossRoutine(1.0f - force.magnitude / maxLength)); } previousVelocity = body.Controller.velocity; previousIsGrounded = body.IsGrounded; transform.localPosition = Vector3.SmoothDamp(transform.localPosition, anchor + force, ref velocity, smoothing); force = Vector3.SmoothDamp(force, Vector3.zero, ref forceVelocity, reduction); }
private IEnumerator Dash() { state = MovementState.DASH; dashChargeCoef = Mathf.Clamp(Time.time - startAttackPress, 0, dashChargeTimeMax) / dashChargeTimeMax; lastDash = Time.time; isDashing = true; rb.gravityScale = 0f; float xcomponent = Mathf.Cos(angle * Mathf.PI / 180); float ycomponent = Mathf.Sin(angle * Mathf.PI / 180); rb.velocity = new Vector2(dashForce * dashChargeCoef * xcomponent, dashForce * dashChargeCoef * ycomponent); yield return(new WaitForSeconds(dashTime)); isDashing = false; rb.gravityScale = gravityScale; Vector3 targetVelocity = new Vector2(0, 0); rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref m_Velocity, 0); }
public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed) { float deltaTime = Time.deltaTime; return(Vector3.SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime)); }