Hello and thank you for any answers and help. I am brand new to Unity and C#. I am trying to learn as I go and am picking up a bit.
How can I clamp this so the player can only scroll the held object a certain distance?
if (Input.GetAxis(“Mouse ScrollWheel”) > 0)
{
holdParent.transform.Translate(Vector3.forward * .3f);
}
if (Input.GetAxis(“Mouse ScrollWheel”) < 0)
{
holdParent.transform.Translate(Vector3.back * .3f);
}
}
Thank you,
KickaPK
Generally: Use Code-Tags to post code.
You can check the distance between a given point (e.g. where your camera is) and the holdParent and only execute the code if the distance is smaller (zooming out) or bigger (zooming in) a certain threshhold. Use Vector3.Distance(a,b) to get the distance or better (performance wise) Vector3.SqrMagnitude(a - b).
if (Input.GetAxis("Mouse ScrollWheel") < 0)
{
if(Vector3.SqrMagnitude(holdParent.transform.position - myCamera.transform.position) > myZoomInThreshhold)
holdParent.transform.Translate(Vector3.back * .3f);
}
Thank you, I got it working.
I will be sure to use code tags in the future.