Adventures In Levitation. (Help me make this work!)

Post » Tue Aug 04, 2015 6:33 am

TranslateTo: I'm still trying to get objects to float when dropped.

I have a duplicate of Meridia's Beacon I'm using as a test object. I added a script to go off when I drop it.

Scriptname dpv_test_levitator extends ReferenceAliasimport debug;; make items float when dropped;float Property height  Autofloat Property speed Autoevent OnContainerChanged(objectReference newref, objectReference oldref)        objectReference ref = getReference()        if newref != none                trace("DPV: picked up " + ref)                gotostate("held")        else                trace("DPV: dropped " + ref)                gotostate("dropped")        endifendeventstate heldendstatestate dropped              ; need to make sure the object's 3D is loaded after being dropped        event OnLoad()                objectReference ref = getReference()                trace("DPV: loaded " + ref)                float x = ref.GetPositionX()                float y = ref.GetPositionY()                float z = ref.GetPositionZ()                ref.translateTo(x, y, z + 1000, 180, 0, 0, speed)                trace("DPV: translating " + ref)        endeventendstate
Doesn't work. I know it gets called when it should, and the translateTo code is executed. Just nothing moves.

So I thought maybe it only works on statics and the like. So I created a movable static version. Stuck that on a table next to a button and gave the button a script to float the gem.


Scriptname dpv_test_lev_button extends ObjectReferenceObjectReference Property Gem  Autoevent OnActivate(objectreference foo)        float x = GetPositionX()        float y = GetPositionY()        float z = GetPositionZ()        translateTo(x, y, z + 1000, 180, 0, 0, 100)endevent
Of course that script http://imgur.com/2ny0EEP,uZ5vSSF,2lFK1No#0 rather than the gem. Still at least I know my code works, right?

Except when I point it back at the gem, nothing happens again.

Any ideas, people? This is rapidly losing its amusemant value

[edit]

It's something about the mesh. If I copy the button and set it to levitate itself, the button levitates. If I change the mesh so it looks like the gem, changing nothing else, then the levitation no longer happens.

What am I missing?
User avatar
Rachel Briere
 
Posts: 3438
Joined: Thu Dec 28, 2006 9:09 am

Post » Tue Aug 04, 2015 2:55 am

setMotionType(4)

The object needs to be keyframed before it will move.
User avatar
gary lee
 
Posts: 3436
Joined: Tue Jul 03, 2007 7:49 pm

Post » Mon Aug 03, 2015 4:15 pm

Objects that have just been dropped (except weapons and something else I've forgotten) don't get their current position in the world tracked properly until the cell reloads. If it still doesn't end up where you expect, you'll want to set it's position relative to the player or you might need to create a duplicate of the original item. Here's what I use to put an item in front of the player in Storage Helpers.

; Place object 150 units directly in front of the player at about table height (75 units).float angZ = PlayerRef.GetAngleZ()float posX = PlayerRef.GetPositionX() + Math.Sin(angZ) * 150float posY = PlayerRef.GetPositionY() + Math.Cos(angZ) * 150float posZ = PlayerRef.GetPositionZ() + 75MovableItem.TranslateTo(posX, posY, posZ, 0.0, 0.0, angZ, speed)
User avatar
cosmo valerga
 
Posts: 3477
Joined: Sat Oct 13, 2007 10:21 am

Post » Mon Aug 03, 2015 8:44 pm

Turns out that ObjectReference has a member variable x that overrides the local variable called x. Rather than the other way around which is what I'd have expected. So my test script was taking its starting co-ords from the button I used to test it.

I changed it to

        float gem_x = ref.GetPositionX()   ; ... and so on
And it started behaving as I'd expected

I did think about placing the gems as you describe, and I can still see benefts. Do you have many problems with items placing through walls and in otherwise inaccessible locations? That was the main thing that stopped me doing it.
User avatar
Krista Belle Davis
 
Posts: 3405
Joined: Tue Aug 22, 2006 3:00 am

Post » Mon Aug 03, 2015 3:49 pm

I've avoided x, y, and z as variable names since the Morrowind days and didn't even think about that.

At a distance of 150 (which is a little farther out than a typical item drop) the containers do sometimes land in walls, but for Storage Helpers that's fine because you always get to adjust the container's position. I'm using 150 because it looks better if the container isn't right at your feet.

For your gems, you would probably want a closer distance probably something around 50 (or maybe 75). Of course if you're putting them 1000 units higher than the player you can put them directly above the player (and I assume placing them only works outside).

User avatar
Nicole Kraus
 
Posts: 3432
Joined: Sat Apr 14, 2007 11:34 pm

Post » Mon Aug 03, 2015 8:51 pm

They're floating up to 120 - I put 1000 in to be sure I'd see an effect. Like maybe I'd misread the wiki page and the parameter was in milliunits or something :smile:

Anyway, I just got it working. This is how it ended up:

Spoiler

Scriptname dpv_gem_levitator extends ReferenceAliasimport debug;; make gems float when dropped;float Property height  Autofloat Property speed Autoevent OnContainerChanged(objectReference newref, objectReference oldref)        objectReference ref = getReference()        if newref != none                trace("DPV: picked up " + ref.getname())                gotostate("held")        else                trace("DPV: dropped " + ref.getname())                gotostate("dropped")        endifendeventfunction try_to_levitate()endfunctionstate held        event OnContainerChanged(objectReference newref, objectReference oldref)                objectReference ref = getReference()                if newref != none                        trace("DPV: picked up " + ref.getname())                        gotostate("held")                else                        trace("DPV: dropped " + ref.getname())                        gotostate("dropped")                endif        endevent        function try_to_levitate()        endfunctionendstatestate dropped        event OnBeginState()                try_to_levitate()        endevent        event OnContainerChanged(objectReference newref, objectReference oldref)                objectReference ref = getReference()                if newref != none                        trace("DPV: picked up " + ref.getname())                        gotostate("held")                else                        trace("DPV: dropped " + ref.getname())                        gotostate("dropped")                endif        endevent        event OnUpdate()                try_to_levitate()        endevent        function try_to_levitate()                objectReference ref = getReference()                trace("DPV: trying to levitate " + ref.getname());;               do we have 3d yet?;                if ! ref.Is3DLoaded()                        RegisterForSingleUpdate(0.1)                        return                endif                trace("DPV: loaded " + ref.getname())                float x = ref.GetPositionX()                float y = ref.GetPositionY()                float z = ref.GetPositionZ()                ref.setMotionType(4)                ref.translateTo(x, y, z + height, 0, 180, 0, speed, 10)                trace("DPV: translating " + ref.getname())        endfunctionendstate
User avatar
chirsty aggas
 
Posts: 3396
Joined: Wed Oct 04, 2006 9:23 am


Return to V - Skyrim