void Update() { var vectorToTarget = target.transform.position - transform.position; var distanceSquared = vectorToTarget.sqrMagnitude; if (distanceSquared < focusDistanceSquared) { var percentOfDistance = (vectorToTarget.magnitude / focusDistance).MapToRange(exclusiveFocusPercentage, 1, 0, 1, true); cameraController.AddInfluence(-vectorToTarget * (1 - percentOfDistance)); } }
void Update() { var inputVector = ((Input.GetAxis(horizontalInput) * Vector3.right) + (Input.GetAxis(verticalInput) * Vector3.forward)).normalized; characterController.Move(inputVector * moveSpeed * Time.deltaTime); var targetLookahead = inputVector * lookahead; currentLookahead.x = Mathf.SmoothDamp(currentLookahead.x, targetLookahead.x, ref lookaheadChangeVelocity.x, lookaheadEaseTime); currentLookahead.y = Mathf.SmoothDamp(currentLookahead.y, targetLookahead.y, ref lookaheadChangeVelocity.y, lookaheadEaseTime); currentLookahead.z = Mathf.SmoothDamp(currentLookahead.z, targetLookahead.z, ref lookaheadChangeVelocity.z, lookaheadEaseTime); cameraController.AddInfluence(currentLookahead); if (Time.time >= changeToNextFrameAt && inputVector.sqrMagnitude > 0) { changeToNextFrameAt = Time.time + animationFrameDelay; currentAnimationFrameIndex++; var scale = spriteRenderer.material.mainTextureScale; scale.x = Mathf.Abs(scale.x); if (flippedHorizontally) { scale.x *= -1; } spriteRenderer.material.mainTextureScale = scale; } // determine facing if (inputVector.x > 0) { spriteRenderer.material.mainTextureOffset = ConvertPositionToOffset(rightFrames[currentAnimationFrameIndex % rightFrames.Length]); flippedHorizontally = false; } else if (inputVector.x < 0) { spriteRenderer.material.mainTextureOffset = ConvertPositionToOffset(leftFrames[currentAnimationFrameIndex % leftFrames.Length]); if (flipLeftSide) { flippedHorizontally = true; } } else if (inputVector.z > 0) { spriteRenderer.material.mainTextureOffset = ConvertPositionToOffset(upFrames[currentAnimationFrameIndex % upFrames.Length]); } else if (inputVector.z < 0) { spriteRenderer.material.mainTextureOffset = ConvertPositionToOffset(downFrames[currentAnimationFrameIndex % downFrames.Length]); } }