Hi guys.
Before you read the problem, please refer to the attached image in order to understand it better.
I have this situation. I must be able to drag a gameobject along a perpendicular line, created by 2 Vector3 points.
As you can see in the image, the points A and B (both are Vector3) are what I use to limit my gameobject movements.
The gameobject starts exatly between points A and B (I use Lerp(A, B, .5f) to put it there) but I can’t limit its drag movement to the perpendicular line.
http://wiki.unity3d.com/index.php/3d_Math_functions
see function for getting a PointOnLine
You project the mouse click position onto the line which is perpendicular to AB
to calculate points C and D on the perp line, you have
C = (A+B)/2
and
vector2 dir = B-A
Vector2 D = C + Vector2(dir.y, -dir.x)
I didn’t mean like that, of course, I meant more what specifically are you stuck on? Is it the math idea to do this? Is it the touch interaction portion? Just looking for some more context around ‘why’ so there is a clear approach to the problem.
What I’m stuck on is on how to limit the cube that I want to drag, to the perpendicular line of A-B.
Currently I can drag the cube around anywhere with this code: