• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[Solved] Creating a Multishot ability (adjusting arrow angles to match # of arrows fired)

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 76
Joined
Aug 10, 2018
Messages
8,351
Hello, I'm terrible at math and wondering if anyone could help me with this trigger. I'm creating a Multishot ability that fires multiple projectiles towards a target point. I want the system to detect how many arrows are to be fired (a variable I want to be able to adjust freely) and then spread them over a 90 degree angle, with one arrow ALWAYS guaranteed to face the targeted point.

So an ideal setup would be that if you fired 3 arrows then one would go down the center, one would face the casters angle -45 degrees and the last one would face the casters angle +45 degrees. The way I have it setup in the trigger below can achieve something close to this but only for an EVEN numbers of arrows. I realize that when dealing with an even number of projectiles it will always look a little weird since there will be 1 extra arrow on either side of the hero, but as long as the center arrow is always aimed towards the targeted point then that's all I care about. This trigger is just an example so don't worry about the leaks and missing variables:

  • multishot test
    • Events
    • Conditions
    • Actions
      • -------- Starting Angle --------
      • Set TempReal1 = ((Angle from (Position of TempUnit1) to ProjectilePoint[(Custom value of TempUnit1)]) - 45.00)
      • -------- Angle Increments --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • HeroStatProjectiles[(Custom value of TempUnit1)] Equal to 1
        • Then - Actions
          • Set TempReal2 = 45.00
        • Else - Actions
          • Set TempReal2 = (90.00 / (Real(HeroStatProjectiles[(Custom value of TempUnit1)])))
      • -------- Create Projectiles --------
      • For each (Integer A) from 1 to HeroStatProjectiles[(Custom value of TempUnit1)], do (Actions)
        • Loop - Actions
          • Set ProjectileCount = (ProjectileCount + 1)
          • Set ProjectileAngle[ProjectileCount] = (TempReal1 + TempReal2)
          • Unit - Create 1 Projectile for TempPlayer1 at TempPoint1 facing ProjectileAngle[ProjectileCount] degrees
          • Set TempReal1 = (TempReal1 + TempReal2)

With the trigger above, if you fired 2 arrows and your hero was facing 90 degrees then the first arrow would face 90 degrees and the second would face 90 + 45 degrees.
 
Last edited:
If an odd number of arrows just divide 90 by arrowcount-1 to get the angular spacing between them; if an even number divide by arrowcount as if it was a 1-bigger odd-numbered arrow spread but leave off the last arrow on one side. This will unfortunately make the arrow spread slightly less than 90 degrees for even-numbered volleys; you could correct for this but IMO the difference would really be negligible as long as arrowcount is bigger than like 4.

  • Set ARROW_COUNT = (Random integer between 2 and 10)
  • Set ARROW_SPREAD = 90.00 //total number of degrees to cover
  • If (All conditions) then (Actions) else (Actions)
    • If - Conditions
      • (ARROW_COUNT mod 2) equal to 0 //modulo here checks if ARROW_COUNT is even
    • Then - Actions
      • Set ANGLE_INC = (ARROW_SPREAD / ARROW_COUNT)
      • -------- ARROW_COUNT = 1 makes a special case here but I presume you don't care about that one --------
    • Else - Actions
      • Set ANGLE_INC = (ARROW_SPREAD / (ARROW_COUNT - 1))
  • Set ANGLE = (angle from caster to target) + 45.00
  • For each (Integer A) from 1 to ARROW_COUNT do (Actions)
    • Loop - Actions
      • Set POINT = (CASTER_LOC offset by 10.00 towards ANGLE degrees)
      • Unit - Create 1 Projectile for PLAYER at POINT facing ANGLE degrees
      • Set ANGLE = (ANGLE - ANGLE_INC)
Don't forget to clean your leaks.
 
Status
Not open for further replies.
Back
Top