• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] make unit move like parabol

Status
Not open for further replies.
Level 3
Joined
Aug 11, 2006
Messages
43
JASS:
function Trig_Mvm_Func001A takes nothing returns nothing
    //local real tfrequency=0.05
    local real tfrequency=t
    local real g=9.8
    
    local real cameraangle
    local real heroagi
    local real to
    
    local real scale=20
    local real ScaleY=scaley
    local real deltatime
    local real Vox
    local real Voy
    local real tmax
    local real Sy
    local real Sx
    local real hprev=0
    local real hnext=0
    local real Zprev
    local real Znext
    set temp_unit_Arrow = GetEnumUnit()
    
    set heroagi=GetUnitUserData(temp_unit_Arrow)
    // set cameraangle=GetUnitState(temp_unit_Arrow, UNIT_STATE_MANA))
    set cameraangle=a
    
    set to=GetUnitState(temp_unit_Arrow, UNIT_STATE_LIFE)/100
    set Vox=evaluateHeroagi(heroagi)*CosBJ(cameraangle)
    set Voy=evaluateHeroagi(heroagi)*SinBJ(cameraangle)
    
    set tmax=Voy/g
    set Sx=Vox*tfrequency*scale
    set deltatime=clock-to
    
   
   if (GetUnitFlyHeight(temp_unit_Arrow)<=2) then
        //call BJDebugMsg("to="+R2S(to)+";deltat="+R2S(deltatime))
        //call BJDebugMsg("Vox="+R2S(Vox)+";Voy="+R2S(Voy))
        //call BJDebugMsg("evaluateHeroagi="+R2S(evaluateHeroagi(heroagi))+";Cos="+R2S(CosBJ(cameraangle)))
        //call BJDebugMsg("evaluateHeroagi="+R2S(evaluateHeroagi(heroagi))+";Sin="+R2S(SinBJ(cameraangle)))
        //call BJDebugMsg("Tmax="+R2S(tmax)+";Sin="+R2S(SinBJ(cameraangle)))
        //call BJDebugMsg("Sx="+R2S(Sx))
        //call BJDebugMsg("A="+R2S(a))
        call impact()
        
   else
        if deltatime<=tmax then
            set Sy=(Voy*tfrequency-g*tfrequency*(2*deltatime-tfrequency)/2)*ScaleY
            
            set Zprev=GetLocationZ(GetUnitLoc(temp_unit_Arrow))
            set hprev=GetUnitFlyHeight(temp_unit_Arrow)+Zprev
            set hnext=hprev+Sy
            set temp_loc_currentpoint=GetUnitLoc(temp_unit_Arrow)
            set temp_loc_destinationpoint=PolarProjectionBJ(temp_loc_currentpoint,Sx,GetUnitFacing(temp_unit_Arrow))
            set Znext=GetLocationZ(temp_loc_destinationpoint)
            call SetUnitFlyHeight(temp_unit_Arrow,hnext-Znext,0)
            call SetUnitPositionLocFacingBJ( temp_unit_Arrow, temp_loc_destinationpoint, GetUnitFacing(temp_unit_Arrow) )
            //call BJDebugMsg("up;hprev="+R2S(hprev)+";hnext="+R2S(hnext))
            //call BJDebugMsg("up;fprev="+R2S(hprev-Zprev)+";fnext="+R2S(hnext-Znext))
            call RemoveLocation(temp_loc_currentpoint)
            call RemoveLocation(temp_loc_destinationpoint)
            set temp_loc_destinationpoint=GetUnitLoc(temp_unit_Arrow) //for use in ArrowDamageUnit
            
            set temp_group_ArrowsBowHit=GetUnitsInRangeOfLocAll(50,temp_loc_destinationpoint)
            call ForGroupBJ(temp_group_ArrowsBowHit, function ArrowDamageUnit)
            call DestroyGroup(temp_group_ArrowsBowHit)
            
        else
            set Sy=g*tfrequency*(2*deltatime-tfrequency)*ScaleY/2
            
            set Zprev=GetLocationZ(GetUnitLoc(temp_unit_Arrow))
            set hprev=GetUnitFlyHeight(temp_unit_Arrow)+Zprev
            set hnext=hprev-Sy
            set temp_loc_currentpoint=GetUnitLoc(temp_unit_Arrow)
            set temp_loc_destinationpoint=PolarProjectionBJ(temp_loc_currentpoint,Sx,GetUnitFacing(temp_unit_Arrow))
            set Znext=GetLocationZ(temp_loc_destinationpoint)
            call SetUnitFlyHeight(temp_unit_Arrow,hnext-Znext,0)
            call SetUnitPositionLocFacingBJ( temp_unit_Arrow, temp_loc_destinationpoint, GetUnitFacing(temp_unit_Arrow) )
            //call BJDebugMsg("down;hprev="+R2S(hprev)+";hnext="+R2S(hnext))
            //call BJDebugMsg("down;fprev="+R2S(hprev-Zprev)+";fnext="+R2S(hnext-Znext))
            call RemoveLocation(temp_loc_currentpoint)
            call RemoveLocation(temp_loc_destinationpoint)
            set temp_loc_destinationpoint=GetUnitLoc(temp_unit_Arrow)//for use in ArrowDamageUnit
            
            set temp_group_ArrowsBowHit=GetUnitsInRangeOfLocAll(50,temp_loc_destinationpoint)
            call ForGroupBJ(temp_group_ArrowsBowHit, function ArrowDamageUnit)
            call DestroyGroup(temp_group_ArrowsBowHit)
            
        endif
       
        
    endif
endfunction

I want to make arrow move like parabol with noise terrain. But it' didn't work. Can someone have solution ?
 

Attachments

  • Real Archer System.w3x
    31 KB · Views: 43
Last edited by a moderator:
Why have you made this code from a converted GUI trigger? You seem to be a beginner in JASS as you use BJs all over the place. You have bad use of locations (all temp locs should be stored as globals and moved to wherever needed. GetUnitsInRangeOfLocAll should be replaced by a group enum using GroupEnumUnitsInRange. You also never null anything, which causes lots of leaks... in short, this isn't programmed very well at all.

A piece of advice: make your script readable before coming to us for advice.
 
Setting handles (anything other than integers, reals, booleans, strings and code) as null at the end of the code deletes that point of memory. If you leave it a local variable with a value at the end of a function, there is then no way to access that variable. If you get a lot of unaccessible variable, your map will begin to lag. These unaccessible points in memory are usually called leaks.
 
Status
Not open for further replies.
Top