Jump to content
Sign in to follow this  
alleycat

line intersect problem

Recommended Posts

I was attempting to do this:

while {true} do
{
_intersect	 =	lineIntersectsWith [getposASL test_canteen, ((getposASL test_canteen) select 2) + 0.2, test_canteen, test_canteen, true];

hintsilent format["_intersect: %1", _intersect];
sleep 1;
};

Error:

while {true} do
{
_intersect	 =	lineIntersectsWith [getposASL test_cante>
14:32:20   Error position: <lineIntersectsWith [getposASL test_cante>
14:32:20   Error 0 elements provided, 3 expected
14:32:20 File C:\Users\cat\Documents\Arma 3\missions\cat_zeus.Altis\line_intersect_test.sqf, line 44
14:32:21 Bad conversion: array
14:32:21 Error in expression <

I dont see what is wrong

Share this post


Link to post
Share on other sites

You mean this part?

((getposASL test_canteen) select 2) + 0.2

I wanted the endpos to be 0.2m above the canteen. I dont see what is wrong with the syntax?

---------- Post added at 02:43 PM ---------- Previous post was at 02:41 PM ----------

Oh wait, now I see it, It was supposed to a complete array of 3 coordinates and I only passed the third one. Thanks for the hint.

Share this post


Link to post
Share on other sites

It needs to be a position like

[(getposASL test_canteen) select 0,(getposASL test_canteen) select 1,((getposASL test_canteen) select 2) + 0.2]

edit:ninja'd by you! :)

Edited by Das Attorney

Share this post


Link to post
Share on other sites

However the lineintersect does not give out the result I hoped for. I was trying to get a touchplate script working that does a simple check on wether a player intersects with a line, originating from a small object and pointing up.

while {true} do
{
_intersect	 =	lineIntersectsWith [
getpos test_canteen, 
[
	(getpos test_canteen) select 0,
	(getpos test_canteen) select 1,
	((getpos test_canteen) select 2) + 2
],
test_canteen, test_canteen, true];


hintsilent format["_intersect: %1", _intersect];
sleep 1;
};

However there is never anything in the array.

Share this post


Link to post
Share on other sites

Getpos returns height above terrain/surface. lineIntersectsWith uses height above sealevel.

So use getposasl instead.

Share this post


Link to post
Share on other sites

Tried this, replaced all getpos to getposASL, but the array still never has anything in it. Am I overlooking something?

Share this post


Link to post
Share on other sites

Thanks for linking model to world. it made the script more compact. However while it did not fix the issue, I found out something by accident, it appears player objects do not trigger lineintersect, however some objects do. I placed an unmanned boat (in zeus mode) and its bounding box intersected, showing in the array. I will try the other line script commands and see if they work with players.

Share this post


Link to post
Share on other sites

You need 4 parameters, not 5. Remove the true in the end (you misread the wiki and mistaked the return value for a parameter). And also it's a waste to have 2 of the same objects to be ignored.

while {true} do
{
       _pos1 = getposASL test_canteen;
       _pos2 = getposASL test_canteen;
       _pos2 set [2, (_pos2 select 2) + 0.2];
_intersect	 =	lineIntersects [_pos1 , _pos2, test_canteen];	
hintsilent format["_intersect: %1", _intersect];
sleep 1;
};

And to add to above post:

lineintersects works perfectly. I use it to determine Line Of Sight between objects.

EDIT:

I misread the post... You used lineIntersectsWith

while {true} do
{
       _pos1 = getposASL test_canteen;
       _pos2 = getposASL test_canteen;
       _pos2 set [2, (_pos2 select 2) + 0.2];
_intersect	 =	lineIntersectsWith[_pos1 , _pos2, test_canteen, objNull, true];	
hintsilent format["_intersect: %1", _intersect];
sleep 1;
};

If you perhaps add a bit height to the first position it won't start on terrain level, which might affect your results - I'll need to test first to see if terrain triggers lineIntersectsWith since it already won't work under water.

But if you can tell us what you want your script to do, we might have a better solution than this.

Edited by Ed

Share this post


Link to post
Share on other sites

I am using a lineIntersect check for triggering caltrops in my mission, so this problem intrigued me as I wasn't aware this didn't work for player objects.

My workaround was to attach an object to the player that's floating and using that as the trigger object for the intersect. LineIntersect doesn't work below ground so I was forced to put it as high as possible so that it's out of sight. In testing this worked as high as 20km, but past maybe 1km you can't see it anyway. Once it's triggered you can just use attachedTo on the trigger object to retrieve the player reference. I used a file, but you might want to use a slightly larger object depending on the tolerance you want.

// Set this however high you want to go
_alt = 2000; 

_origin = player modelToWorldVisual [0,0,_alt];

_trigger = createVehicle ['Land_File1_F', [0,0,0], [], 0, 'CAN_COLLIDE']; 
_trigger attachTo [player, [0,0,(_alt + 0.5)]]; 

_pos1 = ATLtoASL _origin;
_pos2 = ATLtoASL _origin;

// Set one point slightly higher
_pos2 set [2, (_pos2 select 2) + 1];    

while {true} do
{   	
       _intersect = lineIntersectsWith[_pos1, _pos2, objNull, objNull, true];	
hintsilent format["_intersect: %1", _intersect];
sleep 0.1;
};

I used a custom function to render some debug lines so you can see the intersect in action at 2m.

Share this post


Link to post
Share on other sites

Since you are using caltrops then, you can also use nearObjects and check for the caltrops objects. If the players are closer than for instance 0.5m then you damage them. Im assuming you have an object for the caltrops.

Share this post


Link to post
Share on other sites
Since you are using caltrops then, you can also use nearObjects and check for the caltrops objects. If the players are closer than for instance 0.5m then you damage them. Im assuming you have an object for the caltrops.

No, this wasn't accurate enough since the caltrops are 3m long and 0.1m wide. Using the line intersect to draw a line along the extent of the object and raised slightly made it super accurate and trigger exactly when tyres hit it. The above solution I placed to satisfy op's request to use lineIntersect, in this situation nearEntities might be better since the object is small and not elongated or irregular.

Share this post


Link to post
Share on other sites
No, this wasn't accurate enough since the caltrops are 3m long and 0.1m wide. Using the line intersect to draw a line along the extent of the object and raised slightly made it super accurate and trigger exactly when tyres hit it. The above solution I placed to satisfy op's request to use lineIntersect, in this situation nearEntities might be better since the object is small and not elongated or irregular.

Use bounding boxes and test wether the player's bounding box and the caltrops bounding box has intersected.

Share this post


Link to post
Share on other sites
Use bounding boxes and test wether the player's bounding box and the caltrops bounding box has intersected.

I appreciate you taking the time to respond, but I don't need help with this. My first comment was just pointing out how I have used a similar method to OP to use lineIntersects as triggers.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×