I am attempting to move an object using a ray, but only across two axes. I would like to write a solution which uses linear algebra (i.e. dot, cross product etc), but my understanding of this area of games programming and geometry is very limited and I don’t know how to approach this. Obviously, I need to return a new Vector3 position.
The diagram below shows an object O which I want to move. If I were to use a raycast from camera C:
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
I need to find the point along ray R which would be perpendicular to the Object O’s starting point from the camera’s position. Hopefully the diagram explains what I mean. Presumably I need to find the theta angle first, and then I can somehow calculate the distance R and then use ray.GetPoint() to return the new position, but I need a little help with the maths first before I can write this, and I’m drawing a blank. I have never found an explanation of this kind of problem which has made me particularly comfortable with this stuff, and I don’t have any formal training as a programmer. To be honest, it makes me feel pretty stupid that I just can’t seem to get a handle on vectors, so if anyone could help me understand this better I’d be very grateful.
The diagram above is two-dimensional but I’m working in 3D. Hopefully it demonstrates what I’m trying to accomplish anyway.