#Zoom-in Problem

1 messages · Page 1 of 1 (latest)

hollow knot
#

Zoom-in Problem

iron siren
#

right because distance is reduced

#

you have no zoom out condition

#

so make one for zoom in and one for zoom out

#

keep things simple

hollow knot
#

isn't the direction changed if I reverse scroll?

#

cuz normally the zoom-out works. It stops working if I get to the point where I can't zoom-in anymore

iron siren
#

show current script with that again

hollow knot
#
using UnityEngine;

public class CameraController : MonoBehaviour
{
    private float tumbleSpeed = 5f, trackSpeed = 5f, zoomSpeed = 2.5f;
    public GameObject cameraFramePrefab;
    [HideInInspector] public GameObject CameraFrame;

    void Awake()
    {
        CameraFrame = Instantiate(cameraFramePrefab, new Vector3(0f, 0f, 0f), Quaternion.identity);
    }

    void Update()
    {
        Vector3 lookAtPosition = CameraFrame.transform.position;

        // Dolly: Alt + Scroll Wheel
        if (Input.GetKey(KeyCode.LeftAlt) && Input.GetAxis("Mouse ScrollWheel") != 0f)
        {
            float scrollWheel = Input.mouseScrollDelta.y * zoomSpeed;

            Vector3 dollyDirection = lookAtPosition - transform.position;
            if (dollyDirection.magnitude > 5f)
            {
                transform.position += dollyDirection.normalized * scrollWheel;
            }
        }
    }
}```
#

I tried with this if condition as well, still same problem
if (Input.GetKey(KeyCode.LeftAlt))

iron siren
# hollow knot ```cs using UnityEngine; public class CameraController : MonoBehaviour { pr...

I would do

    private void ZoomIn()
    {

        if(Vector3.Distance(transform.position , target.position) > 0.5f) //max zoom in
        {
            var dir = (target.position - transform.position).normalized;

            transform.position += dir * zoomSpeed * Time.deltaTime;
        }

    }

    private void ZoomOut()
    {
        if (Vector3.Distance(transform.position, target.position) < 4f) //max zoom out distance
        {
            var dir = (target.position - transform.position).normalized;
            transform.position -= dir * zoomSpeed * Time.deltaTime;
        }
    }```
#
  private void Update()
    {
        if(Input.mouseScrollDelta.y > 0)
        {
            ZoomIn();
        }else if (Input.mouseScrollDelta.y < 0)
        {
            ZoomOut();
        }
    }```
#

wait no

#

the problem if somehow distance goes under 0.04 somehow it breaks

#

hmm if u put 0.5 instead for max zoom in it works but not a good solution

#

If I had more time Id offer a better solution but gotta run

hollow knot
#

sure thanks

iron siren
#

the main issue is using Distance checks instead of hard coded number inside the movement itself

#

what you can do is keep a certain number that can only go say -10 to 10 or w.e and thats ur forward max movement

#

transform.position += new vector3(0,0, clampedNumber)