Hi
I have a problem which I have been thinking about for some time.
The situation is like this:
I have a screen where I can swipe in order to move the camera. If I swipe in one direction, the camera goes the opposite direction (as I would think is normal for swiping and controlling a camera on a mobile). My problem is that I only want the user to be able to move the camera a certain length from the origin, so I do this:
if (Input.GetMouseButton(0))
{
Vector3 move = Input.mousePosition - previousPos;
// Some calculations done for starposvec2 and currentmaincamvec2 here, removed because they might just cause confusion to my actual problem //
if ((Mathf.Abs((starposvec2 - currentmaincamvec2)) < 50f))
{
MainCam.transform.Translate(-move * Time.deltaTime);
}
starposVec2 is the startposition.magnitude of the maincamera and the currentmaincamvec2 is the current magnitude of the main camera. They are in vector2 because of the way the background is made, but it doesn’t have an effect on my problem.
So my code basically says that it can move as long as the length from the origin is less than 50f. Which of course means that if my finger gets over 50, the camera wont move anymore. If you let go of your finger, the camera returns to it’s original position by some other parts of the code.
I’ve been thinking something in the like of; if it is over 50, then maybe check if the move vector (your current finger velocity) points away from the point where it was locked and then translate it that way. I’m really not sure, I’m pretty stuck.
Cheers