• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Bullet system

Status
Not open for further replies.
Level 12
Joined
Jul 11, 2007
Messages
642
My goal in this system was to make it so bullets can realistically fly and not be affected by terrain. What is wrong with this current system? Explained in triggers:


  • Create
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Shoot Gun
    • Actions
      • Set TP = (Position of (Triggering unit))
      • -------- To make it more inacurate for longer range --------
      • Set P = (Target point of ability being cast)
      • Set FP = (P offset by ((Distance between TP and P) / 50.00) towards (Random angle) degrees)
      • Custom script: call RemoveLocation(udg_P)
      • Unit - Create 1 Bullet for (Owner of (Triggering unit)) at TP facing (Angle from TP to FP) degrees
      • -------- To make it able to change heights --------
      • Unit - Add Crow Form to (Last created unit)
      • Unit - Remove Crow Form from (Last created unit)
      • -------- To make it start the right height --------
      • Animation - Change (Last created unit) flying height to 60.00 at 0.00
      • -------- To calculate angle changed per 1/20th of a second --------
      • Custom script: set udg_Real1 = GetLocationZ(udg_FP)
      • Custom script: set udg_Real2 = GetLocationZ(udg_TP)
      • Set Real3 = ((((Real1 + 60.00) - Real2) / ((Distance between TP and FP) / 1400.00)) / 20.00)
      • -------- The +60 is to have a height offset, the 1400 is the movement per second, and the 20 is that there are 20 moves in a second. --------
      • Unit - Set the custom value of (Last created unit) to (Integer(Real3))
      • Custom script: call RemoveLocation(udg_TP)
      • Custom script: call RemoveLocation(udg_FP)
  • Move
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Bullet
            • Then - Actions
              • Set TP = ((Position of (Picked unit)) offset by 70.00 towards (Facing of (Picked unit)) degrees)
              • Unit - Move (Picked unit) instantly to TP
              • -------- To make the angle adjust --------
              • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + (Real((Point-value of (Picked unit))))) at 0.03
              • Set FP = ((Position of (Picked unit)) offset by 10.00 towards (Facing of (Picked unit)) degrees)
              • -------- To adjust bullet so terrain doesn't affect --------
              • Custom script: set udg_Real1 = GetLocationZ(udg_FP)
              • Custom script: set udg_Real2 = GetLocationZ(udg_TP)
              • Set Real3 = (Real1 - Real2)
              • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + Real3) at 0.02
              • Custom script: call RemoveLocation(udg_TP)
              • Custom script: call RemoveLocation(udg_FP)
            • Else - Actions
  • Collision
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • -------- To make it collide with the ground or make it dissappear when it goes too heigh --------
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Bullet
              • (Current flying height of (Picked unit)) Less than or equal to 3.00
              • (Current flying height of (Picked unit)) Greater than or equal to 450.00
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
If you need an example of how the bullets should fly, play Elimination Tournament.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
I'm not sure if this is the problem, but shouldn't it be
  • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + (Real((Custom Value of (Picked unit))))) at 0.03
instead of

  • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + (Real((Point-value of (Picked unit))))) at 0.03
Instead of Point-Value it should be Custom Value.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Maybe it's your formula in the first trigger:
  • Set Real3 = ((((Real1 + 60.00) - Real2) / ((Distance between TP and FP) / 1400.00)) / 20.00)
Can't you just set the bullets height to 60 then set the bullets Custom Value to 60 + GetLocationZ(TP) and the each time you move just set the bullets height to Custom Value of Picked unit - GetLocationZ(TP)? If you use this the bullet will start with 60 height and it will be affected by terrain elevation as it moves.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
  • Set Real3 = ((((Real1 + 60.00) - Real2) / ((Distance between TP and FP) / 1400.00)) / 20.00)
This should be (Real2 - Real1 + 60)/FPS -> (Real2 - Real1 + 60)/20).
I don't know why you put that /1400 but it made no sense (and it doesn't really matter if it's real2 - real1 or real1 - real2).

Now about the random angle - it might make your bullets VERY inaccurate as it has a very long distance compared to the total distance (well it's own distance).
You might want to make that a bit less random.
 
Level 12
Joined
Jul 11, 2007
Messages
642
HINDYhat also made it with vJASS and you can't use vJASS on a mac. there only is one non-vJASSed physics engine but it was given up a long time ago... You know, I've been reading up on regular JASS... maybe I can get it to work now. I'll try.

EDIT: forget that.. I don't know how to do full JASS yet. And I know I can't dive in with something as complicated as that.
 
Last edited:
Level 29
Joined
Jul 29, 2007
Messages
5,174
  • Set Real3 = ((((Real2 - Real1 + 60)/20) / ((Distance between TP and FP) / 1400.00)) / 20.00)
Ao make it that? Or remove the 1400 aswell?

  • Set Real3 = ((((Real2 - Real1 + 60)/20) / (Distance between TP and FP)) / 20.00)

As I said, a simple (Real2 - Real1 + 60) / 20 should do the job (that's the starting calculation).
If you want this to check for cliffs and Z heights, you will have to put some extra stuff for that.

The point is - you do not want to start calculating it all every time the trigger runs. What you want to do is calculate from the start the correct angle and then check for cliffs when the trigger runs.
For this, check the height of the location the bullet is going to be in the FUTURE. So, create a location at Speed/FPS (70 in this case) towards your angle, check if the new location is higher then the current one, and if it is, remove the bullet, or do whatever effects you want to do with it.

And a second note - why are you putting the removing stuff in another trigger which also runs on 0.05 ? This just makes it harder for the computer and it makes no sense. Put it in the movement trigger.
You also leak two groups every 0.05 seconds in both of the triggers.
Remember to add a "set bj_wantDestroyGroup = true" custom script before picking units.
 
Level 12
Joined
Jul 11, 2007
Messages
642
Ahhhh. I get it.


But the problem that's really bugging me is still here. Here's the new triggers:


  • Create
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Shoot Gun
    • Actions
      • Set TP = (Position of (Triggering unit))
      • -------- To make it more inacurate for longer range --------
      • Set P = (Target point of ability being cast)
      • Set FP = (P offset by ((Distance between TP and P) / 50.00) towards (Random angle) degrees)
      • Custom script: call RemoveLocation(udg_P)
      • Unit - Create 1 Bullet for (Owner of (Triggering unit)) at TP facing (Angle from TP to FP) degrees
      • -------- To make it able to change heights --------
      • Unit - Add Crow Form to (Last created unit)
      • Unit - Remove Crow Form from (Last created unit)
      • -------- To make it start the right height --------
      • Animation - Change (Last created unit) flying height to 60.00 at 0.00
      • -------- To calculate angle changed per 1/20th of a second --------
      • Custom script: set udg_Real1 = GetLocationZ(udg_FP)
      • Custom script: set udg_Real2 = GetLocationZ(udg_TP)
      • Set Real3 = (((Real1 - Real2) + 60.00) / 20.00)
      • -------- The +60 is to have a height offset, the 1400 is the movement per second, and the 20 is that there are 20 moves in a second. --------
      • Unit - Set the custom value of (Last created unit) to (Integer(Real3))
      • Custom script: call RemoveLocation(udg_TP)
      • Custom script: call RemoveLocation(udg_FP)
  • Move
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Bullet
            • Then - Actions
              • Set TP = ((Position of (Picked unit)) offset by 70.00 towards (Facing of (Picked unit)) degrees)
              • Unit - Move (Picked unit) instantly to TP
              • -------- To make the angle adjust --------
              • Unit - Add Crow Form to (Picked unit)
              • Unit - Remove Crow Form from (Picked unit)
              • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + (Real((Point-value of (Picked unit))))) at 0.03
              • Set FP = ((Position of (Picked unit)) offset by 70.00 towards (Facing of (Picked unit)) degrees)
              • -------- To adjust bullet so terrain doesn't affect --------
              • Custom script: set udg_Real1 = GetLocationZ(udg_FP)
              • Custom script: set udg_Real2 = GetLocationZ(udg_TP)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Real1 Greater than (Real2 + (Current flying height of (Picked unit)))
                • Then - Actions
                  • Unit - Remove (Picked unit) from the game
                • Else - Actions
              • Set Real3 = (Real1 - Real2)
              • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + Real3) at 0.02
              • Custom script: call RemoveLocation(udg_TP)
              • Custom script: call RemoveLocation(udg_FP)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Bullet
              • (Current flying height of (Picked unit)) Greater than or equal to 450.00
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
the problem is that the bullet isn't changing height at all... even though I've added crowform to the unit. The height just dosen't change at all from it's original setting after created.
 
Level 12
Joined
Jul 11, 2007
Messages
642
LOL! I thought that was how long it would take it to get to that height. So I thought that meant that in 0.03 seconds it would be that much higher. I'll test it again and then tell you the results.


EDIT: Hmmm.... doesn't exactly work... bullets just want to curve down and the fact that I've made it gain or lose height depending on changes in the terrain does nothing... Let's say X=you, and the lines are the terrain, and the * is where you target. Also the dotted line is the bullet path (of course):

Code:
                /   \   
               /     \    
X------------ /       \             *
_____________/         \_____________
that one is ok, but
Code:
               ------  
           -    /   \   --
         -   * /     \    --
X---------    /       \    --     
_____________/         \___-__________
? What's going on?
 
Level 12
Joined
Jul 11, 2007
Messages
642
Hmm... I rearranged the trigger:
  • Create
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Shoot Gun
    • Actions
      • Set TP = (Position of (Triggering unit))
      • Set P = (Target point of ability being cast)
      • Set FP = (P offset by ((Distance between TP and P) / 50.00) towards (Random angle) degrees)
      • Custom script: call RemoveLocation(udg_P)
      • Unit - Create 1 Bullet for (Owner of (Triggering unit)) at TP facing (Angle from TP to FP) degrees
      • Unit - Add Crow Form to (Last created unit)
      • Unit - Remove Crow Form from (Last created unit)
      • Animation - Change (Last created unit) flying height to 60.00 at 0.00
      • Custom script: set udg_Real1 = GetLocationZ(udg_FP)
      • Custom script: set udg_Real2 = GetLocationZ(udg_TP)
      • Set Real3 = (((Real1 - Real2) / 20.00) + 60.00)
      • Unit - Set the custom value of (Last created unit) to (Integer(Real3))
      • Custom script: call RemoveLocation(udg_TP)
      • Custom script: call RemoveLocation(udg_FP)
  • Move
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Bullet
            • Then - Actions
              • Set TP = (Position of (Picked unit))
              • Unit - Add Crow Form to (Picked unit)
              • Unit - Remove Crow Form from (Picked unit)
              • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + (Real((Point-value of (Picked unit))))) at 0.00
              • Set FP = ((Position of (Picked unit)) offset by 70.00 towards (Facing of (Picked unit)) degrees)
              • Custom script: set udg_Real1 = GetLocationZ(udg_FP)
              • Custom script: set udg_Real2 = GetLocationZ(udg_TP)
              • Set Real3 = (Real1 - Real2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Real1 Greater than (Real2 + (Current flying height of (Picked unit)))
                • Then - Actions
                  • Unit - Remove (Picked unit) from the game
                • Else - Actions
              • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + Real3) at 0.00
              • Unit - Move (Picked unit) instantly to FP
              • Custom script: call RemoveLocation(udg_TP)
              • Custom script: call RemoveLocation(udg_FP)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Bullet
              • (Current flying height of (Picked unit)) Greater than or equal to 450.00
              • (Current flying height of (Picked unit)) Less than or equal to 3.00
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
And I've found that the bullets can only have an angle adjustment down? What is this? Also, whenever I target the other side of this valley:
picture1qz0.png

Should the bullet not simply fly across it without going down? Well.. it goes down, then hits the wall on the other side... could you explain possibly?
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Arg this is so annoying. Blizzard cliffs sure make all this business confusing and stupid.

I *think* (lol) this should work (add it in your pick and change all the Triggering Unit to Picked Unit of course).
Notice that Height_Change is that value you got in the first trigger.
  • Actions
    • Set CurrentPoint = (Position of (Triggering unit))
    • Set NextPoint = (CurrentPoint offset by 70.00 towards (Facing of (Triggering unit)) degrees)
    • Custom script: set udg_Real = GetLocationZ(udg_FuturePoint) - GetLocationZ(udg_CurrentPoint)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Real Greater than ((Current flying height of (Triggering unit)) + Height_Change)
      • Then - Actions
        • Unit - Hide (Triggering unit)
        • Unit - Kill (Triggering unit)
      • Else - Actions
        • Animation - Change (Triggering unit) flying height to ((Current flying height of (Triggering unit)) + (Real + Height_Change)) at 0.00
        • Unit - Move (Triggering unit) instantly to (CurrentPoint offset by (Distance / FPS) towards (Facing of (Triggering unit)) degrees)
 
Level 12
Joined
Jul 11, 2007
Messages
642
Ok...

  • Create
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Shoot Gun
    • Actions
      • Set TP = (Position of (Triggering unit))
      • Set P = (Target point of ability being cast)
      • Set FP = (P offset by ((Distance between TP and P) / 50.00) towards (Random angle) degrees)
      • Custom script: call RemoveLocation(udg_P)
      • Unit - Create 1 Bullet for (Owner of (Triggering unit)) at TP facing (Angle from TP to FP) degrees
      • Unit - Add Crow Form to (Last created unit)
      • Unit - Remove Crow Form from (Last created unit)
      • Animation - Change (Last created unit) flying height to 60.00 at 0.00
      • Custom script: set udg_Real1 = GetLocationZ(udg_FP)
      • Custom script: set udg_Real2 = GetLocationZ(udg_TP)
      • Set Real3 = (((Real1 - Real2) / 20.00) + 60.00)
      • Unit - Set the custom value of (Last created unit) to (Integer(Real3))
      • Custom script: call RemoveLocation(udg_TP)
      • Custom script: call RemoveLocation(udg_FP)
  • Move
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Bullet
            • Then - Actions
              • Set TP = (Position of (Picked unit))
              • Set FP = ((Position of (Picked unit)) offset by 70.00 towards (Facing of (Picked unit)) degrees)
              • Custom script: set udg_Real1 = GetLocationZ(udg_FP) - GetLocationZ(udg_TP)
              • Set Real2 = (Real((Point-value of (Picked unit))))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Real1 Greater than ((Current flying height of (Picked unit)) + Real2)
                • Then - Actions
                  • Unit - Hide (Picked unit)
                  • Unit - Kill (Picked unit)
                • Else - Actions
                  • Animation - Change (Picked unit) flying height to ((Current flying height of (Picked unit)) + (Real1 + Real2)) at 0.00
                  • Unit - Move (Picked unit) instantly to FP
              • Custom script: call RemoveLocation(udg_TP)
              • Custom script: call RemoveLocation(udg_FP)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Bullet
              • (Current flying height of (Picked unit)) Greater than or equal to 450.00
              • (Current flying height of (Picked unit)) Less than or equal to 3.00
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
That clearly is a more efficient code, but I have the same problem... At this point it may be best if I just send you the map:
 

Attachments

  • Bullet System.w3x
    454.3 KB · Views: 73
Level 19
Joined
Aug 24, 2007
Messages
2,888
worst way ever
why do you pick all units in map
create a single group named bullets
when a bullet is created add it to bullets
pick every unit in bullets and do actions
when a bullet dies remove it from bullets
 

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,266
worst way ever
why do you pick all units in map
create a single group named bullets
when a bullet is created add it to bullets
pick every unit in bullets and do actions
when a bullet dies remove it from bullets

I agree, that is how it's done in missile war. The bullets is in a periodic event or a timer. But I don't know how to deal with heights.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
how to deal with heights ?
what do you mean

just if missles height is between targets height + X and targets height - X explode the missle

if you mean calculating height it should reach to hit the target like lunching a cannon ball to a point
its little different
 
Status
Not open for further replies.
Top