• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[vJASS] Make this spell smoother

Status
Not open for further replies.
Level 10
Joined
May 27, 2009
Messages
494
i'm making a spiral moving spell and manage to create a code for it
unfortunately, the movement isn't smooth, the unit is jumping around the points in the circle, still haven't got a right value for it, anyone please help me :D
bjdebugs are for debugs
code:
JASS:
    globals
        private constant integer ABILITY_ID = 'A006'
        private constant integer UNIT_ID = 'h013'
        private constant integer ARROW_MAX = 7//default
        private constant integer MAX_SPIRE = 3
        private constant real MAX_AOE = 425
        private constant real MAX_HEIGHT = 425
        private constant real ARROW_INTERVAL = 0.3
        private constant real INTERVAL = 0.03
        private constant real DISTANCE_INCREMENT = 5
        private group tmpGroup = null
        private real angleDis = 8//360*INTERVAL
        private integer tmpIndex
    endglobals
    
    private struct Arrow
        //! runtextmacro DummyReuser("UNIT_ID","true")
    endstruct
    
    private struct ArrowMove
        unit caster
        Arrow arrow
        integer spire
        real initx
        real inity
        real angle
        real face
        real dist
        real height
        timer time 
        
        static method OnLoop takes nothing returns nothing
            local thistype dat = GetTimerData(GetExpiredTimer())
            local real x1
            local real y1
            local real x2
            local real y2
            if dat.angle+angleDis < 360 then
                set dat.angle = dat.angle + angleDis
                set dat.dist = dat.dist + DISTANCE_INCREMENT
                if dat.height < MAX_HEIGHT then
                    set dat.height = dat.height + 15
                endif
                if dat.dist > MAX_AOE then
                    set dat.dist = MAX_AOE
                endif
                set x1 = dat.initx + dat.dist * Cos(dat.angle)
                set y1 = dat.inity + dat.dist * Sin(dat.angle)
                set x2 = dat.initx + dat.dist * Cos(dat.angle+angleDis)
                set y2 = dat.inity + dat.dist * Sin(dat.angle+angleDis)
                call SetUnitX(dat.arrow.dummy,x1)
                call SetUnitY(dat.arrow.dummy,y1)
                set dat.face = Atan2(y2-y1,x2-x1)
                call SetUnitFacingTimed(dat.arrow.dummy,bj_RADTODEG*dat.face,0)
                call SetUnitFlyHeight(dat.arrow.dummy,dat.height,0)
                call BJDebugMsg(R2S(dat.angle) + " / " + R2S(dat.face))
            elseif dat.spire < MAX_SPIRE then//move forward
                set x1 = dat.initx + (MAX_AOE+100) * Cos(dat.face)
                set y1 = dat.inity + (MAX_AOE+100) * Sin(dat.face)
                call SetUnitX(dat.arrow.dummy,x1)
                call SetUnitY(dat.arrow.dummy,y1)
                set dat.initx = x1
                set dat.inity = y1
                set dat.spire = dat.spire + 1
                set dat.angle = 0
                set dat.dist = 150
                set dat.height = 0
            else
                call dat.arrow.destroy()
                call ReleaseTimer(dat.time)
                call dat.destroy()
            endif
        endmethod
        
        static method start takes unit u, Arrow arw returns thistype
            local thistype dat = thistype.allocate()
            local real x1
            local real y1
            local real x2
            local real y2
            set dat.caster = u
            set dat.arrow = arw
            set dat.initx = GetUnitX(dat.arrow.dummy)
            set dat.inity = GetUnitY(dat.arrow.dummy)
            set dat.angle = 0
            set dat.height = 0
            set dat.face = 0
            set dat.spire = 0
            set dat.dist = 150
            //--------------
            set dat.angle = dat.angle + angleDis
            set dat.dist = dat.dist + DISTANCE_INCREMENT
            if dat.height < MAX_HEIGHT then
                set dat.height = dat.height + 15
            endif
            if dat.dist > MAX_AOE then
                set dat.dist = MAX_AOE
            endif
            set x1 = dat.initx + dat.dist * Cos(dat.angle)
            set y1 = dat.inity + dat.dist * Sin(dat.angle)
            set x2 = dat.initx + dat.dist * Cos(dat.angle+angleDis)
            set y2 = dat.inity + dat.dist * Sin(dat.angle+angleDis)
            call SetUnitX(dat.arrow.dummy,x1)
            call SetUnitY(dat.arrow.dummy,y1)
            set dat.face = Atan2(y2-y1,x2-x1)
            call SetUnitFacingTimed(dat.arrow.dummy,bj_RADTODEG*dat.face,0)
            call SetUnitFlyHeight(dat.arrow.dummy,dat.height,0)
            //-----------------
            set dat.time = NewTimer()
            call SetTimerData(dat.time,dat)
            call TimerStart(dat.time,INTERVAL,true,function thistype.OnLoop)
            return dat
        endmethod
    endstruct
 
Last edited:
Status
Not open for further replies.
Top