// Update is called once per frame void LateUpdate() { if (stopped) { return; } RaycastHit2D hit; float offsetY = 0f; float playerY = 0f; switch (control.GetDirection()) { case Direction.right: hit = Physics2D.Raycast(new Vector2(control.transform.position.x, control.transform.position.y + 10f), Vector3.down, 99f, groundLayer); if (hit.collider != null) { playerY = hit.point.y; } hit = Physics2D.Raycast(new Vector2(control.transform.position.x + aheadCameraDistance, playerY + 10f), Vector3.down, 15f, groundLayer); Debug.DrawLine( new Vector2(control.transform.position.x + aheadCameraDistance, playerY + 10f), new Vector2(control.transform.position.x + aheadCameraDistance, playerY + 10f - 15f), Color.red); if (hit.collider == null) { offsetY = -7f; } target = new Vector2(control.transform.position.x + aheadCameraDistance, playerY + offsetY); break; default: target = new Vector2(control.gameObject.transform.position.x, playerY + offsetY); break; } float posX = Mathf.SmoothDamp(transform.position.x, target.x, ref xVelocity, smoothTimeX); float posY = Mathf.SmoothDamp(transform.position.y, target.y + verticalOffset, ref yVelocity, smoothTimeY); transform.position = new Vector3(posX, posY, transform.position.z); }
private void SetSpriteAngle(float angle) { float finalAngle = control.GetDirection() == Direction.left ? -angle : angle; spriteTransform.localRotation = Quaternion.Euler(spriteTransform.localRotation.eulerAngles.x, spriteTransform.localRotation.eulerAngles.y, finalAngle); }