Dummy Animations + Arc Movement

Kenny

Back for now.
Reaction score
202
Lately I have been mucking around with a projectile system just for kicks. However I am stuck on setting the dummy units animations correctly to get it to face the right angle while moving.

To learn more to go this thread.

Heres my projectile system so far (Still got heaps to do):

JASS:

library ProjectileSystem initializer Init requires T32, Recycle

    globals
        private constant integer MAX_INSTANCES = 8190
        private constant integer DUMMY_UNIT_ID = 'e000'
        private constant integer ENABLE_HEIGHT = 'Amrf'
        private constant real    MAX_COLLISION = 197.00
        private constant real    MAXIMUM_SPEED = 1500.00
        private constant real    FIN_THRESHOLD = 32.00
    endglobals
    
    private interface ProjBase
        method onStart takes nothing returns nothing defaults nothing
        method onFinish takes nothing returns nothing defaults nothing
        method onLoop takes nothing returns nothing defaults nothing
        method onHit takes nothing returns nothing defaults nothing
    endinterface
    
    struct ProjFx[MAX_INSTANCES]
    
        private unit    dum  = null
        private effect  fx   = null
        private real    zang = 0.00
        private boolean kill = false
        
        static method create takes real x, real y, real facing returns thistype
            local thistype this = thistype.allocate()
            
            set this.dum = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),DUMMY_UNIT_ID,x,y,facing * bj_RADTODEG)
            call UnitAddAbility(this.dum,ENABLE_HEIGHT)
            call UnitRemoveAbility(this.dum,ENABLE_HEIGHT)
            call SetUnitX(this.dum,x)
            call SetUnitY(this.dum,y)
           
            return this
        endmethod
        
        method operator dummy takes nothing returns unit
            return this.dum
        endmethod
        
        method operator killdummy= takes boolean bool returns nothing
            set this.kill = bool
        endmethod
        
        method operator scale= takes real value returns nothing
            call SetUnitScale(this.dum,value,0.00,0.00)
        endmethod
        
        method operator owner takes nothing returns player
            return GetOwningPlayer(this.dum)
        endmethod

        method operator owner= takes player p returns nothing
            call SetUnitOwner(this.dum,p,false)
        endmethod

        method operator x takes nothing returns real
            return GetUnitX(this.dum)
        endmethod
        
        method operator y takes nothing returns real
            return GetUnitY(this.dum)
        endmethod
        
        method operator z takes nothing returns real
            return GetUnitFlyHeight(this.dum)
        endmethod
        
        method operator x= takes real value returns nothing
            call SetUnitX(this.dum,value)
        endmethod

        method operator y= takes real value returns nothing
            call SetUnitY(this.dum,value)
        endmethod

        method operator z= takes real value returns nothing
            call SetUnitFlyHeight(this.dum,value,0.00)
        endmethod

        method operator xyangle takes nothing returns real
            return GetUnitFacing(this.dum) * bj_DEGTORAD
        endmethod
        
        method operator xyangle= takes real value returns nothing
            call SetUnitFacing(this.dum,value * bj_RADTODEG)
        endmethod

        method operator zangle takes nothing returns real
            return this.zang
        endmethod

        method operator zangle= takes real value returns nothing
            local integer i = R2I(value * bj_RADTODEG + 90.50)
            
            set this.zang = value
            if i >= 180 then
                set i = 179
            elseif i < 0 then
                set i = 0
            endif

            call SetUnitAnimationByIndex(this.dum,i)
        endmethod
        
        method operator fxpath= takes string newpath returns nothing
            if this.fx != null then
                call DestroyEffect(this.fx)
            endif
            
            if newpath == "" then
                set this.fx = null
            else
                set this.fx = AddSpecialEffectTarget(newpath,this.dum,"origin")
            endif
        endmethod
        
        method flash takes string fx returns nothing
            call DestroyEffect(AddSpecialEffectTarget(fx,this.dum,"origin"))
        endmethod
        
        private method onDestroy takes nothing returns nothing
            if this.fx != null then
                call DestroyEffect(this.fx)
                set this.fx = null
            endif

            if this.kill then
                call KillUnit(this.dum)
            else
                call RemoveUnit(this.dum)
            endif
            
            set this.dum = null
        endmethod

    endstruct
   
    struct ProjCore extends ProjBase
   
        private delegate ProjFx fx = 0
        
        // Projectile Coords.
        private real xP     = 0.00
        private real yP     = 0.00
        private real zP     = 0.00
        
        // Target coords.
        private real xT     = 0.00
        private real yT     = 0.00
        private real zT     = 0.00
        
        // Velocities.
        private real xV     = 0.00
        private real yV     = 0.00
        private real zV     = 0.00
        
        // Movement.
        private real facing = 0.00
        private real pitch  = 0.00
        private real speed  = 0.00
        
        // Distances.
        private real dist   = 0.00
        private real total  = 0.00
        private real done   = 0.00
        private real height = 0.00
        private real resist = 1.00
        
        // Booleans.
        private boolean end = false
        private boolean stp = false
        
        // Static members.
        private static location tempLoc   = null
        private static group    enumGroup = null
        private static real     tempReal  = 0.00
        
        method operator pauseProjectile= takes boolean bool returns nothing
            set this.stp = bool
        endmethod
        
        private method getDist takes real x, real y, real z returns real
            return SquareRoot((this.xP - x) * (this.xP - x) + (this.yP - y) * (this.yP - y) + (this.zP - z) * (this.zP - z))
        endmethod
        
        private method getFacing takes real x, real y returns real
            return Atan2((y - this.yP),(x - this.xP))
        endmethod
        
        private method getPitch takes real x, real y, real z returns real
            return Atan2(SquareRoot((x - this.xP) * (x - this.xP) + (y - this.yP) * (y - this.yP)),(z - this.zP))
        endmethod
    
        private method setVelX takes nothing returns nothing
            set this.xV = Sin(this.pitch) * Cos(this.facing) * this.speed
        endmethod
        
        private method setVelY takes nothing returns nothing
            set this.yV = Sin(this.pitch) * Sin(this.facing) * this.speed
        endmethod
    
        private method setVelZ takes nothing returns nothing
            set this.zV = Cos(this.pitch) * this.speed
        endmethod
        
        static method create takes real x, real y, real z, real facing returns thistype
            local thistype this = thistype.allocate()
            
            set this.fx  = ProjFx.create(x,y,facing)
            set this.z   = z

            set this.xP  = this.x
            set this.yP  = this.y
            set this.zP  = this.z
            
            set this.fxpath = "Abilities\\Weapons\\Arrow\\ArrowMissile.mdl"
            set this.scale  = 2.00
            
            return this
        endmethod
        
        method start takes real x, real y, real z, real speed, real height returns nothing
            set this.xT     = x
            set this.yT     = y
            set this.zT     = z
            
            set this.facing = this.getFacing(this.xT,this.yT)
            set this.pitch  = this.getPitch(this.xT,this.yT,this.zT)
            set this.speed  = speed * T32_PERIOD
            
            set this.dist   = this.getDist(this.xT,this.yT,this.zT)
            set this.total  = this.dist
            set this.height = height
            set this.done   = 0.00
            
            call this.setVelX()
            call this.setVelY()
            call this.setVelZ()
            
            if this.onStart.exists then
                call this.onStart()
            endif
            
            call this.startPeriodic()
        endmethod
        
        private method periodic takes nothing returns boolean
             if this.dist <= FIN_THRESHOLD or this.end then
                if this.onFinish.exists then
                    call this.onFinish()
                endif
                call this.destroy()
                return true
            endif
            
            if this.stp == false then
                if this.onLoop.exists then
                    call this.onLoop()
                endif
                
                set this.xV = this.xV * this.resist
                set this.yV = this.yV * this.resist
                set this.zV = this.zV * this.resist
                
                set this.xP = this.xP + this.xV
                set this.yP = this.yP + this.yV
                
                if this.height == 0.00 then
                    set this.zP = this.zP + this.zV
                else
                    set this.zP = (4.00 * this.height / this.total) * (this.total - this.done) * (this.done / this.total)
                endif
                
                call MoveLocation(thistype.tempLoc,this.xP,this.yP)
                set thistype.tempReal = GetLocationZ(thistype.tempLoc)

                set this.x = this.xP
                set this.y = this.yP
                set this.z = (this.zP - thistype.tempReal)
            
                set this.xyangle = this.facing
                set this.zangle  = Atan2(this.zP - thistype.tempReal,SquareRoot(this.xP * this.xP + this.yP * this.yP))

                set this.dist = this.getDist(this.xT,this.yT,this.zT)
                set this.done = this.done + this.speed
            endif
            
            return false
        endmethod
        
        method terminate takes nothing returns nothing
            set this.end    = true
            set this.fxpath = ""
        endmethod
        
        private method onDestroy takes nothing returns nothing
            call this.fx.destroy()
            set this.end = false
        endmethod
        
        static method doInit takes nothing returns nothing
            set thistype.tempLoc = Location(0.00,0.00)
            set thistype.enumGroup = CreateGroup()
        endmethod
        
        implement T32
    endstruct
    
    private function Init takes nothing returns nothing
        call ProjCore.doInit()
    endfunction
    
endlibrary


So as you probably notice, it is partially a rip off of xefx, however, that part of the system is getting a major overhaul soon enough.

The line I am having problem with is this one:

JASS:

set this.zangle  = Atan2(this.zP - thistype.tempReal,SquareRoot(this.xP * this.xP + this.yP * this.yP))


It only works a little bit (for about 20% of the whole arc). I've tried almost everything, any ideas?

I'm pretty sure it is meant to be:

JASS:

Atan2(ZVelocity,SquareRoot(XVelocity * XVelocity + YVelocity * YVelocity))


But it doesn't seem to work.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top