I am trying to setup a challenge in Lua script, in which the player will have to perform an unpowered landing on a runway.
I want to check if the spacecraft touches down within a specified area and then stops within that area (success). If the vessel goes out of the area while it touches the ground then it is a failure. This way I can allow for "touch'n go" attempts but if the "touch" is outside the specified area then the mission is a failure.
I know how to set it up, if it was just a circular area with a radius R and a central point A with coordinates X and Y.
In this case, the part of the script that checks for the landing, would be something like this:
(pseudo-script)
But how does one set it up for a rectangular area?
The first method I thought, was to setup many small circular areas to cover most of the runway and check if the vessel touches down within those areas. (See pic)
But I'm not sure what the syntax would be so I can check if the vessel touches down within area 1 or within area 2 and so on. Could it be as simple as this?
This syntax doesn't feel right. The vessel could touchdown within area 3 but since R_1 is bigger than 1/2 the width of the runway, it would return a failure instead of a success, wouldn't it?
So my question for this method is: What would be the correct syntax to check if the vessel has touched-down inside any of these areas and "return" a success or a failure if it touches-down outside those areas?
I also thought of something else. Instead of defining many small areas, would it be possible to define a rectangular area using the coordinates of the corners of the runway and then get the coordinates of the vessel (while it is in "groundcontact")?
For example (see pic):
X_1= longitude of corner1
Y_1= latitude of corner1
X_2= longitude of corner2
Y_2= latitude of corner2
X_3= longitude of corner3
Y_3= latitude of corner3
X_4= longitude of corner4
Y_4= latitude of corner4
(This would be easier for North-South or East-West runways since every next corner would have one coordinate the same.)
Then "getaltitude" to determine if vessel has touched-down and have it return its X and Y coordinates to check if they are within the "limits" specified above. It seems to me that this is a better method but I don't even know where to begin as far as the syntax goes.
Any help is much appreciated, thanks in advance.
I want to check if the spacecraft touches down within a specified area and then stops within that area (success). If the vessel goes out of the area while it touches the ground then it is a failure. This way I can allow for "touch'n go" attempts but if the "touch" is outside the specified area then the mission is a failure.
I know how to set it up, if it was just a circular area with a radius R and a central point A with coordinates X and Y.
In this case, the part of the script that checks for the landing, would be something like this:
(pseudo-script)
Code:
TGT_A= coordinates of point A
groundcontact=false
alt=getaltitude
if alt < (number) then groundcontact=true
elseif alt > (number) then groundcontact=false [COLOR="RoyalBlue"]--The altitude determines if the spacecraft has touched-down[/COLOR]
end
end
R_A=getdistance from TGT_A
If groundcontact=true and R_A =< (the radius R) then success
end
If groundcontact=true and R_A > (the radius R) then failure
end [COLOR="RoyalBlue"]--(So far I can determine if the spacecraft has touched-down within the area. Now I can either get vel.x or v:islanded, to check if the vessel has stopped, to complete the challenge and return a "score").[/COLOR]
But how does one set it up for a rectangular area?
The first method I thought, was to setup many small circular areas to cover most of the runway and check if the vessel touches down within those areas. (See pic)
But I'm not sure what the syntax would be so I can check if the vessel touches down within area 1 or within area 2 and so on. Could it be as simple as this?
Code:
TGT_1 = coordinates of point 1
TGT_2 = coordinates of point 2
[COLOR="RoyalBlue"]--and so on[/COLOR]
R_1 = getdistance from center of area 1
R_2 = getdistance from center of area 2
[COLOR="RoyalBlue"]-- ...and so on[/COLOR]
If groundcontact=true and R_1 =< (1/2 the width of the runway) or R_2 =< (1/2 the width of the runway) [COLOR="RoyalBlue"]...and so on[/COLOR] then success
else if R_1 > (1/2 the width of the runway) or R_2 > (1/2 the width of the runway) [COLOR="RoyalBlue"]...and so on[/COLOR] then failure
This syntax doesn't feel right. The vessel could touchdown within area 3 but since R_1 is bigger than 1/2 the width of the runway, it would return a failure instead of a success, wouldn't it?
So my question for this method is: What would be the correct syntax to check if the vessel has touched-down inside any of these areas and "return" a success or a failure if it touches-down outside those areas?
I also thought of something else. Instead of defining many small areas, would it be possible to define a rectangular area using the coordinates of the corners of the runway and then get the coordinates of the vessel (while it is in "groundcontact")?
For example (see pic):
X_1= longitude of corner1
Y_1= latitude of corner1
X_2= longitude of corner2
Y_2= latitude of corner2
X_3= longitude of corner3
Y_3= latitude of corner3
X_4= longitude of corner4
Y_4= latitude of corner4
(This would be easier for North-South or East-West runways since every next corner would have one coordinate the same.)
Then "getaltitude" to determine if vessel has touched-down and have it return its X and Y coordinates to check if they are within the "limits" specified above. It seems to me that this is a better method but I don't even know where to begin as far as the syntax goes.
Any help is much appreciated, thanks in advance.