Comments and answers for "Getting the distance in a known direction"
http://answers.unity.com/questions/1656240/getting-the-distance-in-a-known-direction.html
The latest comments and answers for the question "Getting the distance in a known direction"Comment by JonPQ on JonPQ's comment
http://answers.unity.com/comments/1657037/view.html
red up on dot product and vector product (cross product).
With these two things you can do many powerful vector and point checks.
for example.. take 3 points... 2 are for your wall, the 3rd is for another point on left or right of the wall.
if you zero out the Y height. and turn your 3 points into 2 vectors... one for wall, one for wall point to your other point.
Dot product will give you angle delta, you can use it fro aiming, or field of view checks. and cross product sign of result's Y will give you info about whether your point is on left or right of the wall. (as you discovered)Mon, 12 Aug 2019 16:18:55 GMTJonPQComment by Gaweringo on Gaweringo's comment
http://answers.unity.com/comments/1656476/view.html
Oh ok I used the z of the resulting vector ins$$anonymous$$d of the magnitude.Sat, 10 Aug 2019 16:49:39 GMTGaweringoComment by Gaweringo on Gaweringo's answer
http://answers.unity.com/comments/1656456/view.html
This worked after some time of trying it out. But I have another question. Is it possible to get information about if the *myPoint* is behind the wall, so the Distance should be negative.
So that this points in the right direction:
![Debug of the direction][1]
[1]: /storage/temp/144393-annotation-2019-08-10-174446.pngSat, 10 Aug 2019 15:46:04 GMTGaweringoComment by Captain_Pineapple on Captain_Pineapple's answer
http://answers.unity.com/comments/1656361/view.html
Doesn't the ray.direction has to be normalized? otherwise this might not work.Sat, 10 Aug 2019 10:20:10 GMTCaptain_PineappleComment by sacredgeometry on sacredgeometry's comment
http://answers.unity.com/comments/1656276/view.html
I was thinking like this:
![this](https://i.imgur.com/O$$anonymous$$lapVg.png)
That is supposed to be a right angle but the spline tool doesnt like straight corners.
But either way works. You just have to work with either the surface normal or tangent.Sat, 10 Aug 2019 00:16:22 GMTsacredgeometryAnswer by JonPQ
http://answers.unity.com/answers/1656275/view.html
Distance from point to a line...
Define your wall, by any point on the wall, and a vector along its edge. 'ray'
float distance = Vector3.Cross(ray.direction, myPoint - ray.originPoint).magnitude;Sat, 10 Aug 2019 00:01:47 GMTJonPQComment by Gaweringo on Gaweringo's answer
http://answers.unity.com/comments/1656262/view.html
I knew it would be something with trigonometry.
So you mean i could calculate the distance i need like this?:
![Showing the trigonometry in the example]from the question][1]
I really should know this kind of stuff but thx a lot!
[1]: /storage/temp/144366-screenshot-20190810-012555-photos.jpgFri, 09 Aug 2019 23:28:21 GMTGaweringoAnswer by sacredgeometry
http://answers.unity.com/answers/1656249/view.html
###Trigonometry
> sin(theta) = opposite / hypotenuse
or
> hypotenuse * sin(theta) = opposite
----------
Solve for the opposite. (If thats wrong ... its been a long time since I did trig in school but its on the internet so you can double check)Fri, 09 Aug 2019 22:21:30 GMTsacredgeometry