• 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] Bounce!

Status
Not open for further replies.
Level 9
Joined
Oct 15, 2006
Messages
339
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!
 
Level 10
Joined
Jul 14, 2004
Messages
463
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)
 
Level 5
Joined
May 22, 2006
Messages
150
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)
 
Level 5
Joined
May 22, 2006
Messages
150
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":
JASS:
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.
 
Level 5
Joined
May 22, 2006
Messages
150
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)
 
Status
Not open for further replies.
Top