Frozzled Posted March 15, 2012 Share Posted March 15, 2012 I'm having a bit of an issue with getting an ObjectReference's position (and functions which depend on it, like GetDistance). Basically, whenever I do a check on this MiscObject's position, it reports it as being where it was last placed. For example, if I pick up the item and then drop it again, the position will be correct. However, when I kick it around a bit and check its position again, it still says it's where I dropped it. Turning off Havok for the object dynamically correctly stops it in place, but still reports bad position data with that, too. Does anyone know of a way to force an update, or otherwise return the correct position data? Link to comment Share on other sites More sharing options...
fg109 Posted March 15, 2012 Share Posted March 15, 2012 I suppose you could try using something like this: ObjectReference NewObject = YourMiscObject.PlaceAtMe(DummyObject, 1, false, true) float posx = NewObject.GetPositionX() float posy = NewObject.GetPositionY() float posz = NewObject.GetPositionZ() NewObject.Delete() NewObject = None Link to comment Share on other sites More sharing options...
jwbatey Posted March 15, 2012 Share Posted March 15, 2012 GetDistance doesn't work reliably. You need to get each x/y/z, then calculate it usingdistance = math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1) + (z2-z1) * (z2-z1)) I know this works, because I'm using it to throw miscobjects at a target using Havoc impulses:http://youtu.be/EfbEYfR41Xc(The floating light is the target at the moment) Link to comment Share on other sites More sharing options...
fg109 Posted March 15, 2012 Share Posted March 15, 2012 GetDistance doesn't work reliably. You need to get each x/y/z, then calculate it usingdistance = math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1) + (z2-z1) * (z2-z1)) I know this works, because I'm using it to throw miscobjects at a target using Havoc impulses:http://youtu.be/EfbEYfR41Xc(The floating light is the target at the moment) All the crazy things people think up... :laugh: Link to comment Share on other sites More sharing options...
Frozzled Posted March 15, 2012 Author Share Posted March 15, 2012 I suppose you could try using something like this:ObjectReference NewObject = YourMiscObject.PlaceAtMe(DummyObject, 1, false, true) float posx = NewObject.GetPositionX() float posy = NewObject.GetPositionY() float posz = NewObject.GetPositionZ() NewObject.Delete()NewObject = None Just gave that a whirl, but unfortunately doesn't work. It places the new object at the old position. GetDistance doesn't work reliably. You need to get each x/y/z, then calculate it usingdistance = math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1) + (z2-z1) * (z2-z1)) I know this works, because I'm using it to throw miscobjects at a target using Havoc impulses:http://youtu.be/EfbEYfR41Xc(The floating light is the target at the moment) The problem is getting the coordinates in the first place. Noted for when I get that part working, however! Nice buckets, by the way ;) Link to comment Share on other sites More sharing options...
jwbatey Posted March 15, 2012 Share Posted March 15, 2012 Can you post your code? GetPositionX has worked in every situation I've tried. Papyrus spawned objects, cell references, actors, etc.. Without seeing the code, my only guess is that your code is (for some reason) only running on 'new' objects (like if dropped), and doesn't recheck the position afterwards. As an example, if I grab one of those flying buckets into inventory and then drop it, it won't fly anymore (unless I re-target it) Link to comment Share on other sites More sharing options...
GomuGomu64 Posted March 15, 2012 Share Posted March 15, 2012 (edited) On a side-note, since you guys seem to know what you are talking about, how would you attach a script to an Object? Forgive me for being ignorant, I've not found a way to do it in the way you speak of (Attaching scripts to Papyrus spawned objects, actors, etc.). A link to a tutorial may be available, perhaps? On-topic: To force an update, I'd assume that you would just add : NewObject.Disable() NewObject.Enable() to the part where you want the object to refresh. Edited March 15, 2012 by GomuGomu64 Link to comment Share on other sites More sharing options...
Frozzled Posted March 15, 2012 Author Share Posted March 15, 2012 Scriptname FloatTestScript extends ActiveMagicEffect ObjectReference Property orb Auto Event OnEffectStart(Actor akTarget, Actor akCaster) orb.SetMotionType(orb.Motion_Keyframed) orb.TranslateTo(orb.GetPositionX(), orb.GetPositionY(), orb.GetPositionZ() + 100, 0, 0, 0, 50) EndEvent Event OnEffectFinish(Actor akTarget, Actor akCaster) orb.SetMotionType(orb.Motion_Dynamic, true) EndEvent That's linked to a concentrate-self spell, with the orb being linked to an item in a scene. Link to comment Share on other sites More sharing options...
Frozzled Posted March 15, 2012 Author Share Posted March 15, 2012 On a side-note, since you guys seem to know what you are talking about, how would you attach a script to an Object? Forgive me for being ignorant, I've not found a way to do it in the way you speak of (Attaching scripts to Papyrus spawned objects, actors, etc.). A link to a tutorial may be available, perhaps? Pretty much everything in the editor can have a script associated with it, but I'm not sure how one would go about attaching scripts to dynamically-created objects (quest-instantiated objects aside). On-topic: To force an update, I'd assume that you would just add : NewObject.Disable() NewObject.Enable() to the part where you want the object to refresh. This seems to partly work. From what I can gather, once the item is dropped from the inventory, it does not update its position. However, if the object is disabled and re-enabled, coordinate updates start occurring. Interestingly, it does not affect the first time it's called - as in, disable/enable doesn't appear to update the coordinates immediately, just starts the process of doing so. Link to comment Share on other sites More sharing options...
Frozzled Posted March 15, 2012 Author Share Posted March 15, 2012 Based on your suggestion, I've managed to fix the problem! Applying this script to the item in question will cause the object to re-enable itself when it leaves a container: Scriptname FrozzledPositionFix extends ObjectReference Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) if !akNewContainer Utility.Wait(0.001) Disable(false) Enable(false) endif EndEvent The only downside appears to be that it will flicker once as soon as it does it. Unfortunately, changing it to DisableNoWait, or even just calling Enable on an already-enabled object will not work. I don't know if there's another way of achieving the same thing, but this will certainly do for now - it's probably only noticeable if you're looking for it. Link to comment Share on other sites More sharing options...
Recommended Posts