NeMeSiS 11 Posted September 16, 2013 Lets say i am trying to draw a line from point a to point b (x,y and z coordinates). This point will intersect an object at some point, and there are commands that will tell me if and what it intersects with. However, i am trying the find the position where this intersection takes place. It does not have to be perfectly precise(<0.2m would be my guesstimate). I figured there are 2 solutions: 1) Try the lineIntersects command along the line. However, i cant get my head around the required maths, and do not know to to calculate the required positions i would need to try. 2) Spawn a bullet that will never deflect, has no tracer, does no damage and will not fall down due to gravity, and just keep tracking it until it hits something, the reported position would be close enough. However, this requires me to config such a bullet (not sure how to do that, but should be possible with a couple of days trying and crying :p ), then shooting it along the line. However, i do not know how to find the angle between point a and b, or how to shoot the bullet at that angle. Anyone has any idea how to handle this? :) Share this post Link to post Share on other sites
mantls 2 Posted September 16, 2013 doesnt lineintersect (or intersects in general) return the object(s) with which it (they) intersect? Just use it's location? Share this post Link to post Share on other sites
NeMeSiS 11 Posted September 16, 2013 Unfortunately the position of the object doesnt correspond with the position of the place where the line would intersect with the object (except for very tiny objects). I drew it in paint to make is a bit clearer (as far as my paintskills allow me :) ): Share this post Link to post Share on other sites
das attorney 857 Posted September 16, 2013 EDIT: deleted - obsolete. Share this post Link to post Share on other sites
zapat 54 Posted September 16, 2013 This is easiest by some math. You need 2 positions from each line. You can then write the line equations for both lines and get denom from them, which will give you the intersection point. _x1 = _a select 0; _y1 = _a select 1; _x2 = _b select 0; _y2 = _b select 1; _x3 = _linePosba select 0; _y3 = _linePosba select 1; _x4 = _linePosb select 0; _y4 = _linePosb select 1; _a1 = _y2 - _y1; _b1 = _x1 - _x2; _c1 = _x2 * _y1 - _x1 * _y2; _a2 = _y4 - _y3; _b2 = _x3 - _x4; _c2 = _x4 * _y3 - _x3 * _y4; _denom = _a1*_b2 - _a2*_b1; _is = []; if (_denom != 0) then{_is = [(_b1*_c2 - _b2*_c1)/_denom,(_a2*_c1 - _a1*_c2)/_denom,0]} else { //no intersection }; _is Share this post Link to post Share on other sites
lappihuan 178 Posted September 16, 2013 Use BIS_fnc_dirTo and combinate it with others. Use BIS_fnc_Help in the editor to view other Math functions providet by BIS Share this post Link to post Share on other sites
NeMeSiS 11 Posted September 16, 2013 Thanks guys, i got it to work, the math was a lot easier than i expected. The code needs some cleaning but if anyone is interested i can provide a demomission. It may be too slow for what i am after, so i may try the bulletmethod later anyway. Share this post Link to post Share on other sites
Oce 1 Posted October 9, 2013 NeMeSiS, can you shed a little light on how you managed to get the position of the intersection please? Share this post Link to post Share on other sites
NeMeSiS 11 Posted March 21, 2014 (edited) Since i got multiple requests i am going to post the unfinished version. (I kinda forgot about this whole thing, sorry about that) Demomission can be found here. It is not optimized, and the code is kinda crappy but i figure most people can figure out how it works and change it into something they need. Basically it just tries a lot of positions along a line between 2 objects, starting at object 1 and then slowly going towards object 2, trying lineintersect every time. Once it intersects with something it stops. This can be done more efficiently and more accurate but i just havent got the time. Also, there is a variable called '_penis'. Stepsize is controlled by the distance between obj1 and obj2 (Hell if i know why..), and the '200', by changing that you can change the amount of steps and the accuracy. Too low makes it inaccurate, too high kills performance and makes the script take too long to return a position. Edited March 21, 2014 by NeMeSiS Share this post Link to post Share on other sites