Dear Internet,
I have an object on a 2D plane which I wish to drag along this plane. The plane is not infinite when it comes to placing the object. At first I performed a simple Raycast of the input to determine the hit position on the plane, and then moved the object to this position.
The problem with this approach is that I am often having to view the 2D plane perpendicular, such that the plane is completely flat and so is not seen by the user. For example the plane is on the z-x axis and the camera is also on the z-x axis, looking along the z axis. In this case the ray either misses the plane, or intersects the plane at a very far distance, causing the dragged object to move to an odd position when I cast it to the nearest valid point.
I tried creating a two step process, where the ray is cast onto another plane, facing the camera, centred at the object. Then from this hit position cast on to the original plane. If the camera is perpendicular this works.
An example of this working is:
The camera is facing the plane perpendicular, the input is below the plane. The original ray hits the red plane facing the camera and then the second ray hits the dragged destination point on the yellow plane.
The problem is that this two step process then causes weird behaviour when the camera is not perpendicular, as the first ray can hit the camera-facing plane in the distance.
Here is an example of this not working:
The object is in the distance, thus the red plane facing the camera is in the distance. The original ray hits this and then, when projected again onto the final plane, the dragged location is completely incorrect.
Essentially I need a way to drag an object around a non-infinite plane from any camera angle, including perpendicular. Either the process needs to somehow blend between the two options, or a different approach is needed.
Any suggestions / advice is much appreciated