• 🏆 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!

[JASS] Motion Blur won't work properly

Status
Not open for further replies.
Level 1
Joined
Nov 5, 2008
Messages
7
hey guys

well I have a simple problem here, which I can somehow not solve myself...

I wrote a basic function for a Motion Blur

but somehow, my created dummies don't share the same animation as the main unit does...
and also, the units seem not to have zero collision size Oo

here is the code:

JASS:
//******************************************//
//Blur Motion
//******************************************//
struct fadeAlpha
    unit u
    integer fadeSpeed
    boolean fadeColor
    integer R
    integer G
    integer B
    integer A
    static method create takes unit u, integer fadeSpeed, boolean fadeColor returns fadeAlpha
        local fadeAlpha fA = fadeAlpha.allocate()
        set fA.u = u
        set fA.fadeSpeed = fadeSpeed
        set fA.fadeColor = fadeColor
        set fA.R = 255
        set fA.G = 255
        set fA.B = 255
        set fA.A = 255
        return fA
    endmethod
    method onDestroy takes nothing returns nothing
        set .u = null
    endmethod
endstruct

private function UnitBlurMotion_fadeAlpha_Child takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local fadeAlpha fA = fadeAlpha(GetAttachedStruct1(t))
    if fA.A <= 0 then
        call RemoveUnit(fA.u)
        call PauseTimer(t)
        call DestroyTimer(t)
    else
        if fA.fadeColor then
            set fA.R = fA.R - fA.fadeSpeed
            set fA.G = fA.G - fA.fadeSpeed
            set fA.B = fA.B - fA.fadeSpeed
        endif
        set fA.A = fA.A - fA.fadeSpeed
        call SetUnitVertexColor(fA.u,fA.R,fA.G,fA.B,fA.A)
    endif
    set t = null
endfunction

private function UnitBlurMotion_fadeAlpha takes unit u, integer fadeSpeed, boolean fadeColor, real interval returns nothing
    local timer t = CreateTimer()
    local fadeAlpha fA = fadeAlpha.create(u,fadeSpeed,fadeColor)
    call AttachStruct1(t,fA)
    call TimerStart(t,interval,true,function UnitBlurMotion_fadeAlpha_Child)
    set t = null
endfunction 

private struct MotionBlur
    unit hero
    group imageGroup
    integer images
    integer fadeSpeed
    boolean fadeColor
    real interval
    
    static method create takes unit hero, integer animId, real animSpeed, real animDuration, real interval, boolean fadeColor returns MotionBlur
        local MotionBlur MB = MotionBlur.allocate()
        local integer i      = 0
        local integer images = R2I(animDuration/interval + 0.5)
        local player pl  = GetOwningPlayer(hero)
        local unit d
        set MB.hero = hero
        set MB.imageGroup  = CreateGroup()
        set MB.fadeSpeed   = R2I(255/images + 0.5)
        set MB.fadeColor   = fadeColor
        set MB.interval    = interval
        loop
            exitwhen i > images
            set d = CreateUnit(pl,GetUnitTypeId(hero),0,0,GetUnitFacing(hero))
            call UnitAddAbility(d,'Amrf')
            call UnitRemoveAbility(d,'Amrf')
            call UnitAddAbility(d,'Aloc')
            call SetUnitAnimationByIndex(d,animId)
            call SetUnitTimeScale(d,animSpeed)
            call ShowUnit(d,false)
            call SetUnitPathing(d,false)
            call SetUnitXYZ(d,GetUnitX(hero),GetUnitY(hero),GetUnitZ(hero))
            call PauseUnit(d,true)
            call GroupAddUnit(MB.imageGroup,d)
            set d = null
            set i = i+1
        endloop
        set pl = null
        return MB
    endmethod
    method onDestroy takes nothing returns nothing
        local unit u
        set .hero = null
        call GroupClear(.imageGroup)
        call DestroyGroup(.imageGroup)
        set .imageGroup = null
    endmethod
endstruct

private function UnitBlurMotion_Child takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local MotionBlur MB = MotionBlur(GetAttachedStruct1(t))
    local integer i = 0
    local unit imageUnit
    
    set imageUnit = FirstOfGroup(MB.imageGroup)
    if imageUnit == null then
        call MB.destroy()
        call PauseTimer(t)
        call DestroyTimer(t)
    else
        call SetUnitXYZ(imageUnit,GetUnitX(MB.hero),GetUnitY(MB.hero),GetUnitZ(MB.hero))
        call SetUnitTimeScale(imageUnit,0)
        call GroupRemoveUnit(MB.imageGroup,imageUnit)
        call ShowUnit(imageUnit,true)
        call UnitBlurMotion_fadeAlpha(imageUnit,MB.fadeSpeed,MB.fadeColor,MB.interval)
    endif
    
    set t = null 
endfunction

public function UnitBlurMotion takes unit hero, integer animId, real animSpeed, real animDuration, real interval, boolean fadeColor returns nothing
    local timer t = CreateTimer()
    local MotionBlur MB = MotionBlur.create(hero,animId,animSpeed,animDuration,interval,fadeColor)
    call AttachStruct1(t,MB)
    call TimerStart(t,interval,true,function UnitBlurMotion_Child)
    set t = null
endfunction
//******************************************//
//Blur Motion END
//******************************************//

So where is the reason for my dummy units not to share the animation?!
oh btw here is my call:
JASS:
call WishFunctions_UnitBlurMotion(udg_Wish_XL,4,1,1.,0.1,false)

Furthermore, I don't think this is the most efficient way...
to learn more about vJASS, I would very much appreciate if someone could help me making this functions more efficient =)

thanks in advance!
greetz
Wishmaster

edit:
the #s were somehow created....dunno why ^^
they are gone now
 
Level 1
Joined
Nov 5, 2008
Messages
7
no errors...
it's like, I use it, but the dummies just don't use the animation I want them to use
i could upload a screenshot i guess
and they just have a collision size
I don't understand why... Oo
very strange

edit:
ok I uploaded screenshots to show you what I mean

in this first one, you can clearly see that the images don't have the "attack" animation


this one gives you the evidence that they actually HAVE a collision size, because they are not on the same position as the original hero
 
Last edited:
Level 1
Joined
Nov 5, 2008
Messages
7
ok
what i found out now:
Hidden Units do not use animations.

So i may not hide the image units, then they play the animation
still there is the thing with the collision size Oo

edit:
ok collision size now works too

the new, working, code would now be:
JASS:
//******************************************//
//Blur Motion
//******************************************//
globals
    private unit TempU
endglobals

struct fadeAlpha
    unit u
    integer fadeSpeed
    boolean fadeColor
    integer R
    integer G
    integer B
    integer A
    static method create takes unit u, integer fadeSpeed, boolean fadeColor returns fadeAlpha
        local fadeAlpha fA = fadeAlpha.allocate()
        set fA.u = u
        set fA.fadeSpeed = fadeSpeed
        set fA.fadeColor = fadeColor
        set fA.R = 255
        set fA.G = 255
        set fA.B = 255
        set fA.A = 255
        return fA
    endmethod
    method onDestroy takes nothing returns nothing
        set .u = null
    endmethod
endstruct

private function UnitBlurMotion_fadeAlpha_Child takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local fadeAlpha fA = fadeAlpha(GetAttachedStruct1(t))
    if fA.A <= 0 then
        call RemoveUnit(fA.u)
        call PauseTimer(t)
        call DestroyTimer(t)
    else
        if fA.fadeColor then
            set fA.R = fA.R - fA.fadeSpeed
            set fA.G = fA.G - fA.fadeSpeed
            set fA.B = fA.B - fA.fadeSpeed
        endif
        set fA.A = fA.A - fA.fadeSpeed
        call SetUnitVertexColor(fA.u,fA.R,fA.G,fA.B,fA.A)
    endif
    set t = null
endfunction

private function UnitBlurMotion_fadeAlpha takes unit u, integer fadeSpeed, boolean fadeColor, real interval returns nothing
    local timer t = CreateTimer()
    local fadeAlpha fA = fadeAlpha.create(u,fadeSpeed,fadeColor)
    call AttachStruct1(t,fA)
    call TimerStart(t,interval,true,function UnitBlurMotion_fadeAlpha_Child)
    set t = null
endfunction 

private struct MotionBlur
    unit hero
    group imageGroup
    integer images
    integer fadeSpeed
    boolean fadeColor
    real interval
    
    static method create takes unit hero, integer animId, real animSpeed, real animDuration, real interval, boolean fadeColor returns MotionBlur
        local MotionBlur MB = MotionBlur.allocate()
        local integer i      = 0
        local integer images = R2I(animDuration/interval + 0.5)
        local player pl  = GetOwningPlayer(hero)
        local unit d
        set MB.hero = hero
        set MB.imageGroup  = CreateGroup()
        set MB.fadeSpeed   = R2I(255/images + 0.5)
        set MB.fadeColor   = fadeColor
        set MB.interval    = interval
        loop
            exitwhen i > images
            set d = CreateUnit(pl,GetUnitTypeId(hero),0,0,GetUnitFacing(hero))
            call UnitAddAbility(d,'Amrf')
            call UnitRemoveAbility(d,'Amrf')
            call UnitAddAbility(d,'Aloc')
            call SetUnitAnimationByIndex(d,animId)
            call SetUnitTimeScale(d,animSpeed)
            call SetUnitPathing(d,false)
            call SetUnitXYZ(d,GetUnitX(hero),GetUnitY(hero),GetUnitZ(hero))
            call PauseUnit(d,true)
            call GroupAddUnit(MB.imageGroup,d)
            set d = null
            set i = i+1
        endloop
        set pl = null
        return MB
    endmethod
    method onDestroy takes nothing returns nothing
        local unit u
        set .hero = null
        call GroupClear(.imageGroup)
        call DestroyGroup(.imageGroup)
        set .imageGroup = null
    endmethod
endstruct

private function MBmoveUnits takes nothing returns nothing
    call SetUnitXYZ(GetEnumUnit(),GetUnitX(TempU),GetUnitY(TempU),GetUnitZ(TempU))
endfunction

private function UnitBlurMotion_Child takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local MotionBlur MB = MotionBlur(GetAttachedStruct1(t))
    local integer i = 0
    local unit imageUnit
    
    set TempU = MB.hero
    call ForGroup(MB.imageGroup,function MBmoveUnits)
    
    set imageUnit = FirstOfGroup(MB.imageGroup)
    if imageUnit == null then
        call MB.destroy()
        call PauseTimer(t)
        call DestroyTimer(t)
    else
        call SetUnitXYZ(imageUnit,GetUnitX(MB.hero),GetUnitY(MB.hero),GetUnitZ(MB.hero))
        call SetUnitTimeScale(imageUnit,0)
        call GroupRemoveUnit(MB.imageGroup,imageUnit)
        call UnitBlurMotion_fadeAlpha(imageUnit,MB.fadeSpeed,MB.fadeColor,MB.interval/2.)
    endif
    
    set t = null 
endfunction

public function UnitBlurMotion takes unit hero, integer animId, real animSpeed, real animDuration, real interval, boolean fadeColor returns nothing
    local timer t = CreateTimer()
    local MotionBlur MB = MotionBlur.create(hero,animId,animSpeed,animDuration,interval,fadeColor)
    call AttachStruct1(t,MB)
    set TempG = CreateGroup()
    call TimerStart(t,interval,true,function UnitBlurMotion_Child)
    set t = null
endfunction
//******************************************//
//Blur Motion END
//******************************************//
 
Last edited:
Status
Not open for further replies.
Top