Scriptname vutil_FloatyObjectScript extends ObjectReference {Object will drift up and down}Import UtilityImport GameBool Property bStartAtBottom = False Auto{Set True if drifting down would cause the object to clip through its starting point}Float Property fVel = 20.0 Auto{Base speed at which to drift}Float Property fDriftX = 0.0 Auto{Random drift along X axis}Float Property fDriftY = 0.0 Auto{Random drift along Y axis}Float Property fDriftZ = 40.0 Auto{How far to drift along Z axis}Float fPosX = 0.0Float fPosY = 0.0Float fPosZ = 0.0Float fAngX = 0.0Float fAngY = 0.0Float fAngZ = 0.0Float fTDriftZ = 0.0Event OnLoad() ;Store object's starting position fPosX = GetPositionX() fPosY = GetPositionY() fPosZ = GetPositionZ() fAngX = GetAngleX() fAngY = GetAngleY() fAngZ = GetAngleZ() If bStartAtBottom ;Set the path center to above the starting point fPosZ += fDriftZ / 2 EndIf ; TranslateTo will fail if object's 3d is not completely loaded While !Is3DLoaded() Wait(0.01) EndWhile UpdateTranslation()EndEvent;Use this instead of OnTranslationComplete, otherwise there will be a pause before the object moves again.Event OnTranslationAlmostComplete() UpdateTranslation()EndEventEvent OnCellDetach() CleanUp()EndEventEvent OnUnload() CleanUp()EndEventFunction UpdateTranslation() Float fCPosZ = GetPositionZ() If fCPosZ < fPosZ ;We are below the center point If fDriftX || fDriftY ; We need to drift X and Y as well TranslateTo(fPosX + RandomFloat(-fDriftX,fDriftX), fPosY + RandomFloat(-fDriftY,fDriftY), fPosZ + (fDriftZ / 2),fAngX,fAngY,fAngZ,fVel) Else ; No X or Y drift, RandomFloat is slow so skip it if we don't need it TranslateTo(fPosX, fPosY, fPosZ + (fDriftZ / 2),fAngX,fAngY,fAngZ,fVel) EndIf Else ;We are at or above the center point If fDriftX || fDriftY ; We need to drift X and Y as well TranslateTo(fPosX + RandomFloat(-fDriftX,fDriftX), fPosY + RandomFloat(-fDriftY,fDriftY), fPosZ - (fDriftZ / 2),fAngX,fAngY,fAngZ,fVel) Else ; No X or Y drift, RandomFloat is slow so skip it if we don't need it TranslateTo(fPosX, fPosY, fPosZ - (fDriftZ / 2),fAngX,fAngY,fAngZ,fVel) EndIf EndIfEndFunctionFunction CleanUp() StopTranslation() ; This should keep the object from getting progressively farther from its starting point if the cell is loaded repeatedly MoveToMyEditorLocation()EndFunction
I'm bringing this old thread back to live, since I last worked with this (and followed this thread), I can't seem to figure how to make this work?
Not very used to scripts, so I need to know how to do this - like: Apply script to object X and etc.
I've made a copy of GrandSoulGem and called it LorThal_FlyingGem and I need it to hover up and down and rotate (I'll need this effect for more objects), but applying the script to an object like the Gem crashes my CK.
What do I do?
Cheers!
Found no problem using this script.
I attached it to the grand soul gem (and a modified version) like every other script (right click, edit, scripts tab, add)
The only thing I had to change to make items float was to add a single line to the OnLoad event:
self.SetMotionType(Motion_Keyframed)