#Zoom-in Problem
1 messages · Page 1 of 1 (latest)
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
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
show current script with that again
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))
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
sure thanks