PJMail Posted October 17, 2021 Share Posted October 17, 2021 (edited) I hope the CodeSmiths and AI Package Wranglers out there can give me some inspiration... I need to know when the player is near a destination point so I can run a script procedure (i.e. via an On... event).As I will be in a flying Vertibird that point could be in any x,y,z coordinate - so a straight OndistanceLessThan Event may put me on top of it, or a long way to the side (depending on our relative Z positions). Being on top is bad, so is a long way to the side. Preferably I would like to be within a given radius of it as if it's Z position was the same as mine.There is a (static) objectreference at that point.This object may be many Cells away at the start of travel (so unloaded and it's cell unattached) - or nearby. The reason for this is I must interrupt the standard Vertibird "Hover" AI Procedure when I get near the destination of that "Hover" as flying takes into account MHDT but the stop and hover at the end doesn't. I have no reliable method of placing that hover 'end point' above ground (especially when it is in a far away unloaded cell), so I have to terminate the package before it decides it should now run the 'hover' part and dive underground. (If someone knows a reliable method of detecting ground height at a point in any loaded Cell then I could fix the destination 'onCellAttach' - but there is none that I know of). Alternately I need a Vertibird 'travel' package that does not end in a 'landing' but always takes MHDT into account.My experience is the 'travel' package will automatically start a landing if the destination is near ground. For the reasons above I don't know where 'ground' is so can't make sure that point is well above it. Edited October 17, 2021 by PJMail Link to comment Share on other sites More sharing options...
PJMail Posted October 19, 2021 Author Share Posted October 19, 2021 I seem to be asking hard questions. I will just have to use OndistanceLessThan further away than I want to, to allow for worse case height difference. Link to comment Share on other sites More sharing options...
SKKmods Posted October 19, 2021 Share Posted October 19, 2021 In this scenario I use OnDistanceLessThan and then check the Map distance when it triggers with this function. If too high reregister a lower number and include an OnDistanceGreaterThan bailout to unregister and cleanup if the player buggers off. ;******************************************************************************************************************** ; (pSKK_IBQuest as SKK_IBQuestScript).GetMapDistance() ; UTILITY FUNCTION to calculate the absolute flat plane XY ground distance excluding Z height which is a factor when ; spawning at @9999 height to test for good navmesh. ; The CK function .GetDistance() returns the line of sight distance which includes Z height component Float Function GetMapDistance(ObjectReference akTarget, ObjectReference akDatum ) Float fHypotenuse Float fOpposite Float fDistanceToDatum fHypotenuse = akDatum.GetDistance(akTarget) fOpposite = Math.Abs(akTarget.GetPositionZ() - akDatum.GetPositionZ()) fDistanceToDatum = Math.Sqrt( Math.Pow(fHypotenuse, 2) - Math.Pow(fOpposite, 2) ) Return fDistanceToDatum EndFunction ;******************************************************************************************************************** Link to comment Share on other sites More sharing options...
PJMail Posted October 20, 2021 Author Share Posted October 20, 2021 (edited) Funny - I had implemented exactly what you described (ah - high school geometry), then decided it was overkill for what I needed. The ondistancegreaterthan as a catchall in case something unexpected happens (or player takes control) is a good idea. Thanks. P.S. Am I right in assuming the the 'ondistance...' is a one shot event, so once it fires it is gone (doesn't need a cancel...)? Edited October 20, 2021 by PJMail Link to comment Share on other sites More sharing options...
SKKmods Posted October 20, 2021 Share Posted October 20, 2021 The function description is not clear and I have not tested it so always unregister after it fires, just to be sure (which means you do need to store the object reference pair). Rather chow frames than stack up event registrations. Link to comment Share on other sites More sharing options...
niston Posted October 21, 2021 Share Posted October 21, 2021 When I tested ondistance events for my elevator, they turned out to be one-shot. Link to comment Share on other sites More sharing options...
PJMail Posted October 23, 2021 Author Share Posted October 23, 2021 Thanks niston - good to know. Link to comment Share on other sites More sharing options...
Recommended Posts