Warcraft III resources & community, 2003–2006 · archived

Bounce!

9 posts
#1

Bounce!

Does anyone know how to make a bounce code? Like if you run into a unit/doodad/item/destructible/wall at 45º North-West than you bounce 45º Sounth-West.. Ok, can someone make this for mme, and everyone else who would like a bounce? Is it possible? How about adding all angles?

If you've ever played a maze game you can slide on ice. I plan to have this sliding triger in my map but having a bounce would be so awsome and actually would complete my ideal map. Think of the possibilities and please, somebody help!
#2
The problem is that for a bounce you need a bouncing object with movement direction (that's not the problem) and the angle of the static object at the position of the bounce. That's a bigger problem, because how do you want to get this from a destructible or even a unit? That's difficult. You need a form as simple as possible for collision object, e.g. a circle or even better a rect.
The rest are more or less simple mathematics. 8)
#3
Quite simple... If you ignore, what Waldbär said.
In that case, you will get your code tomorrow.
Else... Well, I would not know how to do that as modell geometrics are not used in Warcraft 3.
(collision size forms a circle for any widget)
#4
or rectangles, with rects ^^
#5
I never encountered such ones. But as you say they exist...

If I got the mathematics right, this should work.
As I am not horribly good in such stuff, it may not work. ^^
Report errors to me.

Trigger "Bounce":
function Trig_Bounce_Unitfilter_Ground takes nothing returns boolean
  return IsUnitType(GetFilterUnit(),UNIT_TYPE_GROUND)
endfunction

function Trig_Bounce_Actions takes nothing returns nothing
  local unit bouncer = GetTriggerUnit()
  local real thisX = GetWidgetX( <reflecting thing> )
  local real thisY = GetWidgetY( <reflecting thing> )
  local real bouncerX = GetUnitX(bouncer)
  local real bouncerY = GetUnitY(bouncer)
  local real vectorX = Cos(GetUnitFacing(bouncer)) + bouncerX
  local real vectorY = SquareRoot(1 - Pow(vectorX - bouncerX,2)) + bouncerY
  local real lineThisBouncerX = thisX - bouncerX
  local real lineThisBouncerY = thisY - bouncerY
  local real angleThisBouncer = Acos(vectorX * lineThisBouncerX + vectorY * lineThisBouncerY / (SquareRoot(Pow(vectorX,2) + Pow(vectorY,2)) * SquareRoot(Pow(lineThisBouncerX,2) + Pow(lineThisBouncerY,2))))
  local real aimedX = Cos(angleThisBouncer) * GetUnitMoveSpeed(bouncer) * 0.75 + thisX
  local real aimedY = SquareRoot(Pow(aimedX - thisX,2) / Pow(Cos(angleThisBouncer),2) - Pow(aimedX - thisX,2))
  call PauseUnit(bouncer,true)
  loop
    call SetUnitPosition(bouncer,bouncerX+(aimedX-bouncerX)/10,bouncerY+(aimedY-bouncerY)/10)
    call TriggerSleepAction(0.005)
    exitwhen SquareRoot(Pow(aimedX - GetUnitX(bouncer),2)+Pow(aimedY - GetUnitY(bouncer),2)) < 30
  endloop
  call PauseUnit(bouncer,false)
  set bouncer = null
endfunction

function InitTrig_Bounce takes nothing returns nothing
  set gg_trg_Bounce = CreateTrigger()
  call TriggerRegisterUnitInRange(gg_trg_Bounce, <reflecting thing> ,30,Filter(function Trig_Bounce_Unitfilter_Ground))
  call TriggerAddAction(gg_trg_Bounce,function Trig_Bounce_Actions)
endfunction


postscript:
Code was horribly wrong (sometimes I feel very stupid ^^) and I worked it over.
I hope, it works now.
#6
rects... aka regions in GUI

just use A Unit Enters a Rect

(TriggerRegisterEnterRectSimple)
#7
bah... I didn't understand anything of your code... I thought you weren't so good in mathematics...

I still don't know the REAL function for Cos and ACos besides comparing size/angle.
#8
Hä?
Did you encounter some odd effect?
Or... No effect?
Or what is it, that you are trying to tell me?

(to be sure: I do not care even a little bit, if these terms are right while the effect looks like it is supposed to do)
#9
Ahn.. nothing.. sorry... I was trying to understand this code in instead of just copy and try...

(maybe my English is horrible :P )