Scn LevitationTestScript
; - - NOT be NPC Friendly

ref me
short doState
short FrameCount
ref myWalk
float myX
float myY
float myZ
float tX
float tY
float tZ
float nX
float nY
float nZ
float myX2
float myY2
float myZ2
float tot
float tot2
float fixZ



float dis

float tick
short temp
float timer 
float idletimer
float idleFrame


short isRun
short StopCount ; used to make sure it was walking for a while



; initial position vector
float xPos
float yPos
float zPos


; fly vector
float dx
float dy
float dz
float dt

; private
float angz
float angx
float angz2
float angx2
float xang
float yang
float zang
float x
float x2
float sin
float cos


begin ScriptEffectStart
	set me to Getself
        set myWalk to LevitationTestActivatorRef
	resetfalldamagetimer

end

begin ScriptEffectUpdate

 set FrameCount to FrameCount + 1
 set tick to ScriptEffectElapsedSeconds
 set timer to timer + tick
 set idletimer to idletimer - tick



	if DoState == 0 && FrameCount > 1
	  ; pickIdle
	   set doState to 1

	elseif doState == 1 && timer > 0.3
		 playgroup idle 1
		set doState to 2
		resetfalldamagetimer

        elseif doState == 2

               set myX to getpos x
               set myY to getpos y
               set myZ to getpos z
               set angz to GetAngle z
               set angx to GetAngle x
	       if angx > 30
                  set angx to 30 ;Prevents too steep of incline
               elseif angx < -30
                  set angx to - 30
               endif

		resetfalldamagetimer

	      if  myX > myX2 + 1 || myX < myX2 - 1 || myY > myY2 + 1 || myY < myY2 - 1  ; - - Player is moving
		 	 if StopCount > 0
	         		playGroup jumploop 1
				setpos Z fixZ
		         myWalk.Enable
               endif
			set StopCount to 0
		else ; - -Player Stopped 
                   if StopCount == 0
				  myWalk.Disable
                      playgroup JumpStart 1           
                   endif
			set StopCount to StopCount + 1
		endif


		if StopCount < 2 ; - - Player Moving, or still for 1 step

                 set myX2 to myX
                 set myY2 to myY
                 set myZ2 to myZ
	           set fixZ to myZ + 4


		if ( angz != angz2 || angx != angx2)
			set angz2 to angz
			set angx2 to angx

			 if zang < angz - 2
			     set zang to zang + angz*0.1
			 elseif zang > angz + 2
			     set zang to zang + angz*0.1
			 endif

        	         if angz > 180
	     		    set angz to (angz) - 360
		  	 endif

     	 	        set x to angz*0.0174532925
			set x2 to x*x
			set sin to x*(1-(x2/6)*(1-(x2/20)*(1-(x2/42)*(1-(x2/72)*(1-x2/110)))))
			set cos to 1-0.5*x2*(1-(x2/12)*(1-(x2/30)*(1-(x2/56)*(1-x2/90))))

			set xang to angx*cos ; uses settings from Horizontal Vector
			set yang to -angx*sin

			myWalk.SetAngle z zang
			myWalk.SetAngle y yang
			myWalk.SetAngle x xang
		  endif


	      myWalk.moveto me 0 0 0
 	      set myZ to me.Getpos z
	      myWalk.Setpos z myZ

              else ; - -Stopped

               setpos Z fixZ
             endif



      endif ; - - doState 2

end


begin ScriptEffectFinish
	 playgroup jumpland 1
	resetfalldamagetimer
end
