ZeroCore Posted June 5, 2019 Share Posted June 5, 2019 (edited) I'm trying to make a script that gets the distance between two movable static objects for the sake of determining distance between a moving object and the other movable static which, for the most part, remains in one place throughout a translation. The basic idea is this: Spell is cast by the player. This spell has its own script that moves an XMarkerheading and the first movable static to a location that the player is looking at. The first movable static then moves to it. The player is standing on the bridge of an airship (like the one from TESA: Redguard that Cyrus fights the final boss fight atop) and the airship then starts translating via TranslateToRef to the XMarkerHeading. The second movable static moves with the airship via MoveTo. There is an update loop that goes on that moves the second movable static to the airship once every second. After this second movable static is moved, the script is supposed to get the distance between the two. If the distance is less than a certain value, the ship is supposed to stop. If not, the ship keeps moving until the distance is below a certain limit. In short: Player casts spell that moves XMarkerHeading to desired location --> same spell moves first movable static object as a marker and sets airship to update on update --> airship's script receives the update and update loop kicks off --> on each update the second movable static moves to the ship, "getDistance" is supposed to go off, the distance between the two movable statics is judged --> if the distance is less than a limit, the ship stops, if not, it keeps going --> if it keeps going, the loop updates and it repeats. Scriptname __0ShipDetection extends ObjectReference ObjectReference Property AirshipMarker Auto ObjectReference Property AirshipMarker2 Auto float DistanceToTarget Event OnTranslationStart() debug.notification("translation started") RegisterForSingleUpdate(0.1) EndEvent Event OnUpdate() AirshipMarker2.MoveTo(self as ObjectReference, abMatchRotation = false) DistanceToTarget = AirshipMarker2.getDistance(AirshipMarker) debug.notification("update " + DistanceToTarget) If (DistanceToTarget <= 1024.0) StopTranslation() UnregisterForUpdate() debug.notification("proximity warning") Else RegisterForSingleUpdate(1) debug.notification("in transit") Endif EndEvent Event OnTranslationComplete() debug.notification("translate done") UnregisterForUpdate() EndEvent The problem is this: GetDistance keeps returning wildly incorrect numbers, up to several quintillion digits off even though both the movable static objects, called AirshipMarker and AirshipMarker2, are both in the same cell and in the same worldspace at all times. On top of this, the variable "DistanceToTarget" is supposed to update and get new information with each cycle of the loop, and it does not; it refuses to update. I don't know what is causing this, especially as they are both movable statics and can be moved around with scripts, and neither one is being affected by "translateTo" or "translateToRef", so there shouldn't be any mid-translation issues with either one. I have observed AirshipMarker2 periodically moving, once per second, to the airship itself, so I know that they are being moved via "moveTo" properly. It seems to be "getDistance" that's the problem, and I really don't know why. For the purpose of testing, at the moment, the airship, its XMarkerHeading, and both indicators are in a custom-made interior cell, a sort of "test chamber" that's a part of a mod that I made a while ago. At any rate, the ship, its XMarkerHeading, and both of its indicators, as I've said, are in the same worldspace at all times. The Airship and both of its markers are of type movable static, and the only thing that isn't is the XMarkerHeading, but that does not have any translation issues either, and I have had it successfully move via "MoveTo" as well without issue. I don't know why "getDistance" is returning such wildly incorrect values. On top of this, with each cycle of the loop, "getDistance" does not update. Its value remains the same after the initial data acquisition. I'm not sure why this is either. Edited June 5, 2019 by ZeroCore Link to comment Share on other sites More sharing options...
Reneer Posted June 5, 2019 Share Posted June 5, 2019 Just a hunch, but my guess is that calling GetDistance immediately after MoveTo is likely the issue. There is also the age-old trick of disabling, moving, and enabling a reference to make sure it updates properly. This can be accomplished in Skyrim by using DisableNoWait(), MoveTo(), and finally EnableNoWait(). Link to comment Share on other sites More sharing options...
ZeroCore Posted June 5, 2019 Author Share Posted June 5, 2019 (edited) Just a hunch, but my guess is that calling GetDistance immediately after MoveTo is likely the issue. There is also the age-old trick of disabling, moving, and enabling a reference to make sure it updates properly. This can be accomplished in Skyrim by using DisableNoWait(), MoveTo(), and finally EnableNoWait().That didn't work; I tried doing that, but the result is the same. I still get a huge number that's way, way off target, and the thing still doesn't get new data with each update; it's like the number is just frozen. Nevermind; I got it working now. It turns out I'd loaded the wrong save. Your advice on disabling and then re-enabling did it. Thanks for the help :) Edited June 5, 2019 by ZeroCore Link to comment Share on other sites More sharing options...
Reneer Posted June 5, 2019 Share Posted June 5, 2019 Glad to hear it. :) Link to comment Share on other sites More sharing options...
Recommended Posts