Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: [Snippet] Parabolic Function  (Read 7063 times)

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 981
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[Snippet] Parabolic Function
« on: January 12, 2012, 09:00:58 PM »
Parabolic function simplified by Spec
Code: jass  [Select]
  1. library ParabolicMovement
  2.  
  3. function ParabolaZ takes real h, real d, real x returns real
  4.   return (4 * h / d) * (d - x) * (x / d)
  5. endfunction
  6.  
  7. endlibrary

I left this function because it allows to understand the formula coefficients...

Code: jass  [Select]
  1. function ParabolicMovement takes real h, real d, real x returns real
  2.     local real a = -4*h/(d*d)
  3.     local real b = 4*h/d
  4.     return a*x*x + b*x
  5. endfunction

This function takes as a parameters the distance that the parabolic movement should move (d) and the maximum height the projectile will flight (h).

So x is a value between 0 and d, and the function will return the height for that value.

As a side note, if x < 0 or x > d then this function will return negative values.

Here's a picture for a better understanding of the parameters:


_____________________________________________________________________


Parabolic movement now taking into account initial and final Z heights.

Code: jass  [Select]
  1. library ParabolicMovement2
  2.  
  3. function ParabolaZ2 takes real y0, real y1, real h, real d, real x returns real
  4.   local real A = (2*(y0+y1)-4*h)/(d*d)
  5.   local real B = (y1-y0-A*d*d)/d
  6.   return A*x*x + B*x + y0
  7. endfunction
  8.  
  9. endlibrary



Notes:
  • This function will return the absolute height and therefore this value should be the height you must set to the unit in the function SetUnitFlyHeight()-y0.
  • In order to obtain a proper parabolic shape, "h" must be greater or equal than the maximum value of "y0" and "y1", but anyways, you're free to play with lower values of "h". "h" is the height when x = d/2 but it's not necessarily the maximum height it will reach, the maximum height will be reached when x = -B/2A.
« Last Edit: January 15, 2012, 10:21:09 AM by moyack »

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: [Snippet] Parabolic Function
« Reply #1 on: January 13, 2012, 12:11:45 PM »
Nice :D

I love simple libraries like these. :)

 

[Snippet] Group Units in line, with distance and optional spread-value

Started by rvonsonsnadtzBoard Codes & Snippets

Replies: 5
Views: 11447
Last post March 13, 2013, 06:52:16 PM
by rvonsonsnadtz
[Snippet] Single Player Detector

Started by moyackBoard Codes & Snippets

Replies: 12
Views: 21008
Last post March 13, 2013, 12:48:49 PM
by Magtheridon96
[Snippet] Simple Unit Indexer

Started by moyackBoard Codes & Snippets

Replies: 17
Views: 25829
Last post September 30, 2013, 08:07:19 AM
by moyack
[Snippet] Disable Transmission Skip

Started by PurgeandfireBoard Codes & Snippets

Replies: 2
Views: 8730
Last post July 02, 2013, 01:34:55 PM
by Purgeandfire
[Snippet] Timed Effects

Started by moyackBoard Codes & Snippets

Replies: 0
Views: 7398
Last post January 09, 2012, 07:03:32 PM
by moyack
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!