• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Knockback 2D problems.

Status
Not open for further replies.
Level 17
Joined
Dec 11, 2014
Messages
2,004
JASS:
function godown takes nothing returns nothing
 local integer i = 1
    loop
     exitwhen i > udg_Slide_i
       if udg_Slide_u[i] != null then
        call SetUnitFlyHeight(udg_Slide_u[i], 0, (GetUnitFlyHeight(udg_Slide_u[i]) / udg_Slide_r[udg_Slide_i]))
        set udg_Slide_u[i] = null
       endif
      set i = i + 1
    endloop
endfunction


function slide takes unit u, real height, real dur, location where returns nothing
 local location l = GetUnitLoc(u)
 local real ddur = dur / 2
 local timer t = CreateTimer()
 local real dx = GetLocationX(where) - GetLocationX(l)
 local real dy = GetLocationY(where) - GetLocationY(l)
     if height > 0 then
       if height != 0 then
        set udg_Slide_i = udg_Slide_i + 1
        set udg_Slide_u[udg_Slide_i] = u
        set udg_Slide_r[udg_Slide_i] = ddur
        call SetUnitFlyHeight(u, height, height / ddur)
        call TimerStart(t, ddur, false, function godown)
       endif
      set udg_Knockback2DAngle = bj_RADTODEG * Atan2(GetLocationY(where) - GetLocationY(l), GetLocationX(where) - GetLocationX(l))
      set udg_Knockback2DTime = dur
      set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)
      set udg_Knockback2DUnit = u
      call TriggerExecute(gg_trg_Knockback_2D)
     endif
 call RemoveLocation(l)
 set l = null
 set t = null
endfunction

JASS:
function Look takes unit u, real startx, real starty, real startz, real endx, real endy, real endz, real dur returns nothing
 local location l = Location(startx, starty)
 local unit dum = CreateUnitAtLoc(Player(15), 'n000', l, 270)
 local real dx = GetLocationX(Location(endx, endy)) - GetLocationX(Location(startx, starty))
 local real dy = GetLocationY(Location(endx, endy)) - GetLocationY(Location(startx, starty)) 
      set udg_Knockback2DAngle = bj_RADTODEG * Atan2(GetLocationY(Location(endx, endy)) - GetLocationY(Location(startx, starty)), GetLocationX(Location(endx, endy)) - GetLocationX(Location(startx, starty)))
      set udg_Knockback2DTime = dur
      set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)
      set udg_Knockback2DUnit = dum
      call TriggerExecute(gg_trg_Knockback_2D)
      call SetUnitFlyHeight(dum, startz, 0)
      if dur == 0 then
      call SetUnitFlyHeight(dum, endz, 0)
      else
      call SetUnitFlyHeight(dum, endz, endz / dur)
      endif
      call SetUnitLookAt(u, "bone_head", dum, 0, 0, 0) 
  set udg_LookDum_Int = udg_LookDum_Int + 1
  set udg_LookDum[udg_LookDum_Int] = dum
 call RemoveLocation(l)
 set l = null
 set dum = null
endfunction

In these examples I have 2 Problems:


  1. When a unit is near my Knockbacked unit, it will be swiped to the so they wont collide, what I want it to be the opposite (Walking timed into a gate and the gate moves XD or even when looking somewhere the target slowly moves XDer)
  2. Is the Distance doubled? Do I have to use a n / 2 Before all set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)? Or maybe this has problems (which is weird if so)?
    JASS:
        // Yea, this is DistanceBetweenPoints(locA, locB)
        local real dx = GetLocationX(locB) - GetLocationX(locA)
        local real dy = GetLocationY(locB) - GetLocationY(locA)
        return SquareRoot(dx * dx + dy * dy)

Any help is appreciated.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
The tabbing actually hurts my eyes. *_*

Also... you leak a big ass pile of locations.

Also: GetLocationX(Location(endx, endy))
You wot?

I think the problem can be inside gg_trg_Knockback_2D

I also suggest you to try out one of the existing knockback supporting systems.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
@Wietlol, Knockback 2D is already approved.

@Arad, I am about to release a pretty massive overhaul of Knockback 2D. There will no longer be a need for all that custom object editor data, either. I also found an error I made years ago when transposing Berb's formula from Knockback Lite, so maybe that is what you're experiencing (an inaccuracy in distance, if I understand you?)
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
@Arad, I am about to release a pretty massive overhaul of Knockback 2D. There will no longer be a need for all that custom object editor data, either. I also found an error I made years ago when transposing Berb's formula from Knockback Lite, so maybe that is what you're experiencing (an inaccuracy in distance, if I understand you?)

Yes.
Does the update mean that now it's fixed?
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
Well, I think using a new KD2D with fixed things would mess things up, So that I'll have to recalculate everything. Therefore, I ONLY need to fix the pathing knockback thing.

When a unit is near my Knockbacked unit, it will be swiped to the so they wont collide, what I want it to be the opposite (Walking timed into a gate and the gate moves XD or even when looking somewhere the target slowly moves XDer)
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
Thanks! Will check and configure :)


EDIT: Everything and the new features seem cool, but... Ehm... the Guy isn't moving. Not at all.

JASS:
      set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)
      call BJDebugMsg(R2S(SquareRoot(dx * dx + dy * dy)))

This isn't working, it looks like. (also, It's always returning 256.00, any ideas?)

I really need help for this, Else I'll have to use the old version as it used to work. Also, tick-tack! Time is flying and I only 1 month more to create my cinematic.
 
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Arad, if the only thing you changed to make them stop moving was updating Knockback 2D, you probably have odd terrain or doodads displacing the SetItemPosition checks. Otherwise, any way to show the source of where these functions are being called from?

I can also help you with the coding aspect of this script a little bit since I can tell you're new with JASS. You don't need to give me credits on the project since I won't be doing any creative input, but if by helping you I can improve my own resource that would be invaluable.
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
Arad, if the only thing you changed to make them stop moving was updating Knockback 2D, you probably have odd terrain or doodads displacing the SetItemPosition checks. Otherwise, any way to show the source of where these functions are being called from?

I can also help you with the coding aspect of this script a little bit since I can tell you're new with JASS. You don't need to give me credits on the project since I won't be doing any creative input, but if by helping you I can improve my own resource that would be invaluable.

I only updated. The Whole terrain has absolutely no Pathing (it's a cinematic). Sources (First few Lines of the cinematic with the slide calls):

JASS:
 function Act1F5 takes nothing returns nothing
 local location DHpos = GetUnitLoc(udg_DH)
 local real x = GetLocationX(DHpos) + 256 * Cos(GetUnitFacing(udg_DH) * bj_DEGTORAD)
 local real y = GetLocationY(DHpos) + 256 * Sin(GetUnitFacing(udg_DH) * bj_DEGTORAD)
 local real r = 1.167 * (1 / 0.3)
   call SetUnitAnimationByIndex(udg_DH, 2)
   call slide(udg_DH, 256, r, Location(x, y))
   call CameraSetupApplyForceDuration(gg_cam_Cam_7, true, r)
   call Wait(r)
  call RemoveLocation(DHpos)
  set DHpos = null
 endfunction
 
 function Act1F4 takes nothing returns nothing
 local real r = 1.134 * (1 / 0.3)
   call SetUnitAnimationByIndex(udg_DH, 8)
   call SetUnitFacingTimed(udg_DH, 180, r)
   call CameraSetupApplyForceDuration(gg_cam_Cam_6, true, r)
   call Wait(r)
 endfunction

 function Act1F3 takes nothing returns nothing
  local location DHpos = GetUnitLoc(udg_DH)
  local real x = GetLocationX(DHpos) + 256 * Cos(GetUnitFacing(udg_DH) * bj_DEGTORAD)
  local real y = GetLocationY(DHpos) + 256 * Sin(GetUnitFacing(udg_DH) * bj_DEGTORAD)
  local real r = 1.113 * (1 / 0.3)
   call CameraSetupApplyForceDuration(gg_cam_Cam_4, true, 0)
   call CameraSetupApplyForceDuration(gg_cam_Cam_5, true, r)
   call SetUnitTimeScale(udg_DH, 0.3)
   call SetUnitTimeScale(gg_unit_nhef_0015, 0.3)
   call SetUnitAnimationByIndex(udg_DH, 3)
   call slide(udg_DH, 256, r, Location(x, y))
   call Wait(r)
  call RemoveLocation(DHpos)
  set DHpos = null
 endfunction

 function Act1F2 takes nothing returns nothing
  call CameraSetupApplyForceDuration(gg_cam_Cam_3, true, 4)
  call Wait(4)
 endfunction
 
 function Act1F1 takes nothing returns nothing
    call CinematicFade(bj_CINEFADETYPE_FADEIN, 2, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 100, 100, 100, 0)
    call CameraSetupApplyForceDuration(gg_cam_Cam_1, true, 0)
    call CameraSetupApplyForceDuration(gg_cam_Cam_2, true, 4)
    call Wait(4)
 endfunction
 
 function EndFade takes nothing returns nothing
     if (bj_cineFadeContinueTimer != null) then
        call DestroyTimer(bj_cineFadeContinueTimer)
    endif

    if (bj_cineFadeFinishTimer != null) then
        call DestroyTimer(bj_cineFadeFinishTimer)
    endif
    call SetCineFilterTexture("Ls.tga")
    call SetCineFilterBlendMode(BLEND_MODE_BLEND)
    call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
    call SetCineFilterStartUV(0, 0, 1, 1)
    call SetCineFilterEndUV(0, 0, 1, 1)
    call SetCineFilterStartColor(255, 255, 255, 255)
    call SetCineFilterEndColor(0, 0, 0, 255)
    call SetCineFilterDuration(2)
    call DisplayCineFilter(true)
    call Wait(2)
 endfunction
 
 function Initializer takes nothing returns nothing
 local timer t = CreateTimer()
     call StopMusic(false)
     call ClearMapMusic()
     call StopMusic(false)
     call PlayMusic(gg_snd_Nightsong)
        if (not bj_cineModeAlreadyIn) then
            set bj_cineModeAlreadyIn = true
            set bj_cineModePriorSpeed = GetGameSpeed()
            set bj_cineModePriorFogSetting = IsFogEnabled()
            set bj_cineModePriorMaskSetting = IsFogMaskEnabled()
            set bj_cineModePriorDawnDusk = bj_useDawnDuskSounds
            set bj_cineModeSavedSeed = GetRandomInt(0, 1000000)
        endif
        if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
            call ClearTextMessages()
            call ShowInterface(false, 0)
            call EnableUserControl(false)
            call EnableOcclusion(false)
            call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UNITMOVEMENT,  bj_CINEMODE_VOLUME_UNITMOVEMENT)
            call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UNITSOUNDS,    bj_CINEMODE_VOLUME_UNITSOUNDS)
            call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_COMBAT,        bj_CINEMODE_VOLUME_COMBAT)
            call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_SPELLS,        bj_CINEMODE_VOLUME_SPELLS)
            call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UI,            bj_CINEMODE_VOLUME_UI)
            call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_MUSIC,         bj_CINEMODE_VOLUME_MUSIC)
            call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_AMBIENTSOUNDS, bj_CINEMODE_VOLUME_AMBIENTSOUNDS)
            call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_FIRE,          bj_CINEMODE_VOLUME_FIRE)
        endif
        call SetGameSpeed(bj_CINEMODE_GAMESPEED)
        call SetMapFlag(MAP_LOCK_SPEED, true)
        call FogMaskEnable(false)
        call FogEnable(false)
        call EnableWorldFogBoundary(false)
        set bj_useDawnDuskSounds = false
        call SetRandomSeed(0)
        call UnitAddAbility(udg_DH, 'Arav')
        call UnitAddAbility(udg_VM, 'Arav')
        call UnitAddAbility(udg_DHy, 'Arav')
        call CinematicFade(bj_CINEFADETYPE_FADEOUT, 0, "Ls.tga", 100, 100, 100, 0)
        call TimerStart(t, 2, false, function EndFade)
 endfunction

P.S. New Look:
JASS:
function Look takes unit u, real startx, real starty, real startz, real endx, real endy, real endz, real dur returns nothing
 local location l = Location(startx, starty)
 local unit dum = CreateUnitAtLoc(Player(15), 'n000', l, 270)
 local real dx = endx - startx
 local real dy = endy - starty
      set udg_Knockback2DAngle = bj_RADTODEG * Atan2(dy, dx)
      set udg_Knockback2DTime = dur
      set udg_Knockback2DDistance = SquareRoot(dx * dx + dy * dy)
      set udg_Knockback2DUnit = dum
      call TriggerExecute(gg_trg_Knockback_2D)
      call SetUnitFlyHeight(dum, startz, 0)
      if dur == 0 then
      call SetUnitFlyHeight(dum, endz, 0)
      else
      call SetUnitFlyHeight(dum, endz, endz / dur)
      endif
      call SetUnitLookAt(u, "bone_head", dum, 0, 0, 0) 
  set udg_LookDum_Int = udg_LookDum_Int + 1
  set udg_LookDum[udg_LookDum_Int] = dum
 call RemoveLocation(l)
 set l = null
 set dum = null
endfunction


EDIT: OH NO!!! IT'S NOT EVEN WORKING WITH THE PREVIOUS KB2D NOW! HEEEEEEELP Made it to work. Didn't set the abilities right XD
 
Status
Not open for further replies.
Top