• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] A question as to why the unit isn't moving.

Status
Not open for further replies.

Br0

Br0

Level 4
Joined
May 4, 2012
Messages
102
I do not really know JASS that well, and wouldn't mind some help trying to figure this out... Thank you, and I was wondering if there is a easier way to doing this like in GUI to loop it to 50 balls instead of manually doing it? I want to do it in JASS of course, but just do not know how to loop it for JASS. I actually wanted to convert the sample trigger to GUI for easier use for me.

EDIT: How come one ball moves while the other stays in one spot?

[jass=Trig1]
constant function BouncyPeriod takes nothing returns real
return 0.01
endfunction

function BouncyBallMove takes nothing returns nothing
local integer array vectors
local location stupid //required to get the terrainheight
local real h
local effect eff

// retrieve vector data from unit's custom value
set vectors[1]=GetUnitUserData(udg_BouncyBall)
set vectors[2]=R2I(VectorGetX(vectors[1]))
set vectors[3]=R2I(VectorGetY(vectors[1]))
set vectors[4]=R2I(VectorGetZ(vectors[1]))

// change the ball's position according to it's speed
call VectorAdd(vectors[2], vectors[3])
// change the balls speed by the gravity acceleration
call VectorAdd(vectors[3], vectors[4])

// get terrain height at the position of the ball
set stupid = Location(VectorGetX(vectors[2]), VectorGetY(vectors[2]))
set h = GetLocationZ(stupid)
call RemoveLocation(stupid)
set stupid = null

// verify terrain collision
if h >= VectorGetZ(vectors[2]) then
// get terrain normal vector
set vectors[5]=VectorGetTerrainNormal(VectorGetX(vectors[2]), VectorGetY(vectors[2]), 32.0)
// get the component of speed vector that is perpendicular to the terrain
set vectors[6]=VectorProjectVector(vectors[3], vectors[5])
// invert the ball's speed component that's perpendicular to terrain
call VectorScale(vectors[6], -2.0)
call VectorAdd(vectors[3], vectors[6])
// cleanup the temporary vectors
call VectorDestroy(vectors[5])
call VectorDestroy(vectors[6])
// add land effect
set eff = AddSpecialEffect("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", VectorGetX(vectors[2]), VectorGetY(vectors[2]))
call DestroyEffect(eff)
endif

// move the ball
call SetUnitX(udg_BouncyBall, VectorGetX(vectors[2]))
call SetUnitY(udg_BouncyBall, VectorGetY(vectors[2]))
call SetUnitFlyHeight(udg_BouncyBall, VectorGetZ(vectors[2])-h, 0.0)

endfunction

function BouncyBallCreate takes nothing returns nothing
local integer array vectors
local timer t
set udg_BouncyBall = CreateUnit(Player(0), 'ewsp', 0.0,0.0,0.0)

// make it possible to change the unit's flyheight
call UnitAddAbility(udg_BouncyBall, 'Amrf')
call UnitRemoveAbility(udg_BouncyBall, 'Amrf')

// create the unit's position vector
set vectors[1]=VectorCreate(0.0,0.0,100.0)

// create the unit's starting speed vector
set vectors[2]=VectorCreate(GetRandomReal(-100.0, 100.0)*BouncyPeriod(),GetRandomReal(-100.0, 100.0)*BouncyPeriod(),500.0*BouncyPeriod())

// create the gravity acceleration vector
set vectors[3]=VectorCreate(0.0, 0.0, -800.0*BouncyPeriod()*BouncyPeriod())

// to avoid having too many variables, we store these vectors into another vector
set vectors[4]=VectorCreate(I2R(vectors[1]), I2R(vectors[2]), I2R(vectors[3]))
call SetUnitUserData(udg_BouncyBall, vectors[4])

set t = CreateTimer()
call TimerStart(t, BouncyPeriod(), true, function BouncyBallMove )
endfunction



//===========================================================================
function InitTrig_Bouncy_Ball takes nothing returns nothing
set gg_trg_Bouncy_Ball = CreateTrigger( )
call BouncyBallCreate()
endfunction

[/code]



[jass=Trig2]
constant function BouncyPeriod2 takes nothing returns real
return 0.01
endfunction

function BouncyBallMove2 takes nothing returns nothing
local integer array vectors
local location stupid //required to get the terrainheight
local real h
local effect eff

// retrieve vector data from unit's custom value
set vectors[7]=GetUnitUserData(udg_BouncyBall2)
set vectors[8]=R2I(VectorGetX(vectors[7]))
set vectors[9]=R2I(VectorGetY(vectors[7]))
set vectors[10]=R2I(VectorGetZ(vectors[7]))

// change the ball's position according to it's speed
call VectorAdd(vectors[8], vectors[9])
// change the balls speed by the gravity acceleration
call VectorAdd(vectors[9], vectors[10])

// get terrain height at the position of the ball
set stupid = Location(VectorGetX(vectors[8]), VectorGetY(vectors[8]))
set h = GetLocationZ(stupid)
call RemoveLocation(stupid)
set stupid = null

// verify terrain collision
if h >= VectorGetZ(vectors[8]) then
// get terrain normal vector
set vectors[10]=VectorGetTerrainNormal(VectorGetX(vectors[8]), VectorGetY(vectors[8]), 32.0)
// get the component of speed vector that is perpendicular to the terrain
set vectors[12]=VectorProjectVector(vectors[9], vectors[11])
// invert the ball's speed component that's perpendicular to terrain
call VectorScale(vectors[12], -2.0)
call VectorAdd(vectors[9], vectors[12])
// cleanup the temporary vectors
call VectorDestroy(vectors[11])
call VectorDestroy(vectors[12])
// add land effect
set eff = AddSpecialEffect("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", VectorGetX(vectors[8]), VectorGetY(vectors[8]))
call DestroyEffect(eff)
endif

// move the ball
call SetUnitX(udg_BouncyBall2, VectorGetX(vectors[8]))
call SetUnitY(udg_BouncyBall2, VectorGetY(vectors[8]))
call SetUnitFlyHeight(udg_BouncyBall2, VectorGetZ(vectors[8])-h, 0.0)

endfunction

function BouncyBallCreate2 takes nothing returns nothing
local integer array vectors
local timer t
set udg_BouncyBall2 = CreateUnit(Player(0), 'ewsp', 0.0,0.0,0.0)

// make it possible to change the unit's flyheight
call UnitAddAbility(udg_BouncyBall2, 'Amrf')
call UnitRemoveAbility(udg_BouncyBall2, 'Amrf')

// create the unit's position vector
set vectors[7]=VectorCreate(0.0,0.0,100.0)

// create the unit's starting speed vector
set vectors[8]=VectorCreate(GetRandomReal(-100.0, 100.0)*BouncyPeriod2(),GetRandomReal(-100.0, 100.0)*BouncyPeriod2(),500.0*BouncyPeriod2())

// create the gravity acceleration vector
set vectors[9]=VectorCreate(0.0, 0.0, -800.0*BouncyPeriod2()*BouncyPeriod2())

// to avoid having too many variables, we store these vectors into another vector
set vectors[10]=VectorCreate(I2R(vectors[7]), I2R(vectors[8]), I2R(vectors[9]))
call SetUnitUserData(udg_BouncyBall, vectors[10])

set t = CreateTimer()
call TimerStart(t, BouncyPeriod2(), true, function BouncyBallMove2 )
endfunction



//===========================================================================
function InitTrig_Bouncy_Ball_Copy takes nothing returns nothing
set gg_trg_Bouncy_Ball_Copy = CreateTrigger( )
call BouncyBallCreate2()
endfunction
[/code]
 

Attachments

  • VectorFunctions2.w3x
    26.1 KB · Views: 43
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765

[jass=Trig2]
constant function BouncyPeriod2 takes nothing returns real
return 0.01
endfunction

function BouncyBallMove2 takes nothing returns nothing
local integer array vectors
local location stupid //required to get the terrainheight
local real h
local effect eff

// retrieve vector data from unit's custom value
set vectors[7]=GetUnitUserData(udg_BouncyBall2)
set vectors[8]=R2I(VectorGetX(vectors[7]))
set vectors[9]=R2I(VectorGetY(vectors[7]))
set vectors[10]=R2I(VectorGetZ(vectors[7]))

// change the ball's position according to it's speed
call VectorAdd(vectors[8], vectors[9])
// change the balls speed by the gravity acceleration
call VectorAdd(vectors[9], vectors[10])

// get terrain height at the position of the ball
set stupid = Location(VectorGetX(vectors[8]), VectorGetY(vectors[8]))
set h = GetLocationZ(stupid)
call RemoveLocation(stupid)
set stupid = null

// verify terrain collision
if h >= VectorGetZ(vectors[8]) then
// get terrain normal vector
set vectors[10]=VectorGetTerrainNormal(VectorGetX(vectors[8]), VectorGetY(vectors[8]), 32.0)
// get the component of speed vector that is perpendicular to the terrain
set vectors[12]=VectorProjectVector(vectors[9], vectors[11])
// invert the ball's speed component that's perpendicular to terrain
call VectorScale(vectors[12], -2.0)
call VectorAdd(vectors[9], vectors[12])
// cleanup the temporary vectors
call VectorDestroy(vectors[11])
call VectorDestroy(vectors[12])
// add land effect
set eff = AddSpecialEffect("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", VectorGetX(vectors[8]), VectorGetY(vectors[8]))
call DestroyEffect(eff)
endif

// move the ball
call SetUnitX(udg_BouncyBall2, VectorGetX(vectors[8]))
call SetUnitY(udg_BouncyBall2, VectorGetY(vectors[8]))
call SetUnitFlyHeight(udg_BouncyBall2, VectorGetZ(vectors[8])-h, 0.0)

endfunction

function BouncyBallCreate2 takes nothing returns nothing
local integer array vectors
local timer t
set udg_BouncyBall2 = CreateUnit(Player(0), 'ewsp', 0.0,0.0,0.0)

// make it possible to change the unit's flyheight
call UnitAddAbility(udg_BouncyBall2, 'Amrf')
call UnitRemoveAbility(udg_BouncyBall2, 'Amrf')

// create the unit's position vector
set vectors[7]=VectorCreate(0.0,0.0,100.0)

// create the unit's starting speed vector
set vectors[8]=VectorCreate(GetRandomReal(-100.0, 100.0)*BouncyPeriod2(),GetRandomReal(-100.0, 100.0)*BouncyPeriod2(),500.0*BouncyPeriod2())

// create the gravity acceleration vector
set vectors[9]=VectorCreate(0.0, 0.0, -800.0*BouncyPeriod2()*BouncyPeriod2())

// to avoid having too many variables, we store these vectors into another vector
set vectors[10]=VectorCreate(I2R(vectors[7]), I2R(vectors[8]), I2R(vectors[9]))
call SetUnitUserData(udg_BouncyBall, vectors[10])

set t = CreateTimer()
call TimerStart(t, BouncyPeriod2(), true, function BouncyBallMove2 )
endfunction



//===========================================================================
function InitTrig_Bouncy_Ball_Copy takes nothing returns nothing
set gg_trg_Bouncy_Ball_Copy = CreateTrigger( )
call BouncyBallCreate2()
endfunction
[/code]
Be aware that vectoring through so many balls will cause lag. Im not good with vectors but theres one problem i can see

call SetUnitUserData(udg_BouncyBall, vectors[10]) -> call SetUnitUserData(udg_BouncyBall2, vectors[10])
 
  • Like
Reactions: Br0

Br0

Br0

Level 4
Joined
May 4, 2012
Messages
102
I tried changing the unit variable, didn't work... Kind of clueless when it comes to JASS. Thank you for all the replies everyone.

EDIT: I have solved my problem with this system, thank you again everyone.
 
works fine, paste this in 'another' trigger...

JASS:
constant function BouncyPeriod2 takes nothing returns real
    return 0.01
endfunction

function BouncyBallMove2 takes nothing returns nothing
    local integer array vectors
    local location stupid //required to get the terrainheight
    local real h
    local effect eff

  //  retrieve vector data from unit's custom value
    set vectors[1]=GetUnitUserData(udg_BouncyBall2)
    set vectors[2]=R2I(VectorGetX(vectors[1]))
    set vectors[3]=R2I(VectorGetY(vectors[1]))
    set vectors[4]=R2I(VectorGetZ(vectors[1]))
    
    //  change the ball's position according to it's speed
    call VectorAdd(vectors[2], vectors[3])
  //  change the balls speed by the gravity acceleration
    call VectorAdd(vectors[3], vectors[4])

  //  get terrain height at the position of the ball
    set stupid = Location(VectorGetX(vectors[2]), VectorGetY(vectors[2]))
    set h = GetLocationZ(stupid)
    call RemoveLocation(stupid)
    set stupid = null

  //  verify terrain collision
    if h >= VectorGetZ(vectors[2]) then
      //  get terrain normal vector
        set vectors[5]=VectorGetTerrainNormal(VectorGetX(vectors[2]), VectorGetY(vectors[2]), 32.0)
      //  get the component of speed vector that is perpendicular to the terrain
        set vectors[6]=VectorProjectVector(vectors[3], vectors[5])
      //  invert the ball's speed component that's perpendicular to terrain
        call VectorScale(vectors[6], -2.0)
        call VectorAdd(vectors[3], vectors[6])
      //  cleanup the temporary vectors
        call VectorDestroy(vectors[5])
        call VectorDestroy(vectors[6])
      //  add land effect
        set eff = AddSpecialEffect("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", VectorGetX(vectors[2]), VectorGetY(vectors[2]))
        call DestroyEffect(eff)
    endif

  //  move the ball
    call SetUnitX(udg_BouncyBall2, VectorGetX(vectors[2]))
    call SetUnitY(udg_BouncyBall2, VectorGetY(vectors[2]))
    call SetUnitFlyHeight(udg_BouncyBall2, VectorGetZ(vectors[2])-h, 0.0)
    
    

endfunction

function BouncyBallCreate2 takes nothing returns nothing
    local integer array vectors
    local timer t
    set udg_BouncyBall2 = CreateUnit(Player(0), 'ewsp', 0.0,0.0,0.0)

  //  make it possible to change the unit's flyheight
    call UnitAddAbility(udg_BouncyBall2, 'Amrf')
    
    call UnitRemoveAbility(udg_BouncyBall2, 'Amrf')
    

  //  create the unit's position vector
    set vectors[1]=VectorCreate(0,0,50)

  //  create the unit's starting speed vector
    set vectors[2]=VectorCreate(1,1,3)

  //  create the gravity acceleration vector
    set vectors[3]=VectorCreate(0,0,-0.1)

  //  to avoid having too many variables, we store these vectors into another vector
    set vectors[4]=VectorCreate(I2R(vectors[1]), I2R(vectors[2]), I2R(vectors[3]))
    
    call SetUnitUserData(udg_BouncyBall2, vectors[4])

    set t = CreateTimer()
    call TimerStart(t, BouncyPeriod2(), true, function BouncyBallMove2 )
endfunction

//===========================================================================
function InitTrig_Bouncy_Ball_Copy takes nothing returns nothing
    set gg_trg_Bouncy_Ball = CreateTrigger(  )
    call BouncyBallCreate2()
endfunction
 
Status
Not open for further replies.
Top