In this tutorial, we go over how to find the direction of a mouse swipe in all directions, how to move the camera freely with the mouse position, and how to click and drag cubes. 

This is all handled in the class below.


When the mouse button is first pressed, the position of it is set to the variable. Then a raycast is performed. We first want to see if the click hits any objects in the game world. If it did not, then when the button is released a swipe check is performed. At anytime if the user presses space bar the camera view moves with the mouse. If the mouseState is true, meaning we clicked an object, then that object is moved in conjunction with the mouse. The variable curSreenSpace is the x,y coordinate of the mouse on the screen view. To figure out the movement of the cube when we move the mouse, it is converted to a world point with the offset added to match up the positions. Then the cube is moved.


DragView allows the mouse axis to be tracked and whenever the mouse is moving (!=0) the current game object is moved, in this case the camera. RaycastObject is a basic raycast check to see if the mouse clicked on an object.


Once we let go of our mouse button and nothing has been clicked, a swipe is calculated. We log the mouse position then subtract it from the vector of the first position to see if there is movement. Normalize gives us a value from 0-1 so we can easily check for movement. First if x is greater than y, then we are moving in the x so then we can figure out if we are moving positively or negatively in the x direction and move the camera accordingly while keeping track of how far the camera can move. Same with the y.

A basic lerp function controls camera movement.