• 🏆 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!

[Solved] Distance & Projectile Speed Calculation?

Status
Not open for further replies.
Level 5
Joined
Dec 30, 2022
Messages
36
Hello,

I am trying to set up a formula that will cause a unit's attack projectile to always land 3 seconds after it is thrown.

I thought that setting projectile speed to (distance between attacker & target) / 3 would work, but it's not correct for all distances. For context, the distance range I need to account for is from ~200 to 2,300.

Thanks!
 
Level 39
Joined
Feb 27, 2007
Messages
5,023
(distance between attacker & target) / 3
As long as projectile speed is in the XY plane (has no Z component), then this should be correct. As far as I can tell, speed is XY only; it does not depend on the "projectile arc" setting (ranges from 0 to 1) for a unit's attack. I made two archmages with 300 projectile speed, one with 0 arc one with 1 arc, and they both impacted the same target at the same time. I suppose there could be some sort of timing component if the target is at a different Z height than the source? Didn't test that.

Is this for actually setting a unit's projectile speed before an attack fires, or are you generating a projectile yourself (or using some sort of a projectile launch system)?

Projectile speed is an integer to the game, so it can't go below 1. It is probably also capped at 10000 like projectile-based spells are. Anything in that range should work fine, though. The numbers you provided above would result in speeds of 67 and 767.
 
Level 5
Joined
Dec 30, 2022
Messages
36
As long as projectile speed is in the XY plane (has no Z component), then this should be correct. As far as I can tell, speed is XY only; it does not depend on the "projectile arc" setting (ranges from 0 to 1) for a unit's attack. I made two archmages with 300 projectile speed, one with 0 arc one with 1 arc, and they both impacted the same target at the same time. I suppose there could be some sort of timing component if the target is at a different Z height than the source? Didn't test that.

Is this for actually setting a unit's projectile speed before an attack fires, or are you generating a projectile yourself (or using some sort of a projectile launch system)?

Projectile speed is an integer to the game, so it can't go below 1. It is probably also capped at 10000 like projectile-based spells are. Anything in that range should work fine, though. The numbers you provided above would result in speeds of 67 and 767.
This is for setting a unit's projectile speed before the attack fires.

Won't ever need it to go below 1, and won't ever be anywhere close to the cap (max of 767 like you said).

So i found an interesting solution. I was originally using a for loop like this:
  • For each (Integer D10FBLoopInt) from 25 to 1, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • D10ProjectileDist Greater than or equal to ((Real(D10FBLoopInt)) x 100.00)
        • Then - Actions
          • Unit - Set Unit: D10FBTempUnit's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:0 to Value: (((Real(D10FBLoopInt)) x 100.00) / 3.00)
        • Else - Actions
But then switched it to this:
  • For each (Integer D10FBLoopInt) from 1 to 25, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • D10ProjectileDist Greater than or equal to ((Real(D10FBLoopInt)) x 100.00)
        • Then - Actions
          • Unit - Set Unit: D10FBTempUnit's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:0 to Value: (((Real(D10FBLoopInt)) x 100.00) / 3.00)
        • Else - Actions
And it's working fine now. Also had to adjust the plane so the area all had the same Z. Unfortunately now in the worst case I am updating the unit's projectile speed 25 times, which im guessing takes some sort of toll on the game processing, but not sure if there's a way around it.


Thanks for the help!
 
Level 5
Joined
Dec 30, 2022
Messages
36
Just kidding, I just added another condition to the loop so it's not updating every time if the distance is at the max value (2500 or greater) and figured I would share the final product :)

  • For each (Integer D10FBLoopInt) from 1 to 25, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • D10ProjectileDist Greater than or equal to ((Real(D10FBLoopInt)) x 100.00)
          • D10ProjectileDist Less than (((Real(D10FBLoopInt)) + 1.00) x 100.00)
        • Then - Actions
          • Unit - Set Unit: D10FBTempUnit's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:0 to Value: (((Real(D10FBLoopInt)) x 100.00) / 3.00)
        • Else - Actions
 
Level 39
Joined
Feb 27, 2007
Messages
5,023
So i found an interesting solution. I was originally using a for loop like this:

But then switched it to this:
Both of those parts you showed are identical.
And it's working fine now. Also had to adjust the plane so the area all had the same Z.
With a moderate amount of conic sections math and/or 2D kinematics you could account for variable Z in launch/impact location.
Unfortunately now in the worst case I am updating the unit's projectile speed 25 times, which im guessing takes some sort of toll on the game processing, but not sure if there's a way around it.
A few actions at a frequency of 25 per 3 seconds will absolutely not matter to the game. You could up it to 100/3 and it would be more continuous without affecting performance. 0.0325 is a very common timer period for doing much more complex stuff than this.

I still have to ask "why?", though. Can the target unit really move so much that the timing is off by an amount that matters to the player?
 
Level 5
Joined
Dec 30, 2022
Messages
36
Both of those parts you showed are identical.
No one for loop was set 25-1, and the other was 1-25. 25-1 was not working.

I still have to ask "why?", though. Can the target unit really move so much that the timing is off by an amount that matters to the player?
The "Why" is an artillery projectile that targets the ground in random areas, needs to be 3 seconds regardless of distance for reaction time purposes.

Also thanks for the frequency info.. good to know.
 
Level 39
Joined
Feb 27, 2007
Messages
5,023
The "Why" is an artillery projectile that targets the ground in random areas, needs to be 3 seconds regardless of distance for reaction time purposes.
Then there is absolutely no reason you need to constantly update the unit's projectile speed once it is in flight. The target can't move because it's using attack-ground, and the source moving once it's fired has no effect on the projectile in any way... so the start and endpoints are fixed. That distance tells you the speed you need to use to get exactly 3 seconds.

Are you trying to constantly update the projectile speed so that it is already correct whenever the source unit just happens to attack? If that's the case then the ground target wouldn't be known beforehand so I don't think you're doing this. I imagine you are ordering the source unit to attack ground at a particular location, so in the trigger where you do that you just need to set projectile speed once right before the order is issued. There's no need for anything to happen periodically.

For that matter you're looping from 1-25 without a wait or some delay in the loop (which is usually not something you want anyway) and the only thing that loop does is update the projectile speed... so the first 24 runs of the loop don't matter because their effects are immediately overwritten.
 
Level 5
Joined
Dec 30, 2022
Messages
36
Then there is absolutely no reason you need to constantly update the unit's projectile speed once it is in flight. The target can't move because it's using attack-ground, and the source moving once it's fired has no effect on the projectile in any way... so the start and endpoints are fixed. That distance tells you the speed you need to use to get exactly 3 seconds.

Are you trying to constantly update the projectile speed so that it is already correct whenever the source unit just happens to attack? If that's the case then the ground target wouldn't be known beforehand so I don't think you're doing this. I imagine you are ordering the source unit to attack ground at a particular location, so in the trigger where you do that you just need to set projectile speed once right before the order is issued. There's no need for anything to happen periodically.

For that matter you're looping from 1-25 without a wait or some delay in the loop (which is usually not something you want anyway) and the only thing that loop does is update the projectile speed... so the first 24 runs of the loop don't matter because their effects are immediately overwritten.
Sorry I think you are not understanding what I was trying to do - but the question I asked here is solved.. ty :wthumbsup:
 
Level 39
Joined
Feb 27, 2007
Messages
5,023
I very much think you don't understand what you're doing. As I said: the endpoint is fixed because it's attacking ground. The start point is fixed because that's how wc3 works. The projectile speed should never need to change once the projectile has fired to always get a 3s impact wherever you want. And you are doing an entire loop that overwrites itself every time without any delay between them so the loop has no purpose.
 
Level 5
Joined
Dec 30, 2022
Messages
36
I very much think you don't understand what you're doing. As I said: the endpoint is fixed because it's attacking ground. The start point is fixed because that's how wc3 works. The projectile speed should never need to change once the projectile has fired to always get a 3s impact wherever you want. And you are doing an entire loop that overwrites itself every time without any delay between them so the loop has no purpose.

Circling back on this - the projectile speed adjustment is done BEFORE launch so that the "Attack ground" artillery attack on the unit I am adjusting lands exactly 3 seconds after the attack is triggered.

So the trigger looks like:
1. pick random point X in area
2. create dummy artillery unit
3. adjust projectile speed with calculation
4. order unit to attack random point X

Hope that clears the confusion :)
 
Level 39
Joined
Feb 27, 2007
Messages
5,023
That is what I was explaining that you needed to do.

Your previous replies in this thread implied that you were (or still are?) trying to change projectile speed either while the projectile is in flight or using some sort of a loop that altered the projectile speed 25 times.

If you have removed this code then you can ignore me, but I’m trying to tell you both of those things are pointless for your application.
 
Level 5
Joined
Dec 30, 2022
Messages
36
That is what I was explaining that you needed to do.

Your previous replies in this thread implied that you were (or still are?) trying to change projectile speed either while the projectile is in flight or using some sort of a loop that altered the projectile speed 25 times.

If you have removed this code then you can ignore me, but I’m trying to tell you both of those things are pointless for your application.
At no point was I ever trying to change projectile speed mid-flight. From my first reply to you:

This is for setting a unit's projectile speed before the attack fires.

I'm not sure why you're so deadset on thinking i'm trying to change the speed mid flight. Not only did I clearly state several times my intentions, but also marked the thread as solved, meaning I was able to make a projectile land after 3 seconds regardless of distance, which is the question I was asking help on. If you're trolling for a reaction then you got it.
 
Level 39
Joined
Feb 27, 2007
Messages
5,023
  1. You never posted a full trigger here (only small sections), so the scope of what you were doing is not clear. Many times on these forums people say "I am doing X" and then show code that explicitly does not do X because either they actually intend to do Y or because they don't realize they are doing Y instead.

  2. You have never explained what you were trying to accomplish with your 1-25 loop despite me asking about it multiple times, so I have been trying to make sense of it in case you are doing something unnecessary. The only thing I can logically think for it to do to modify the projectile speed over time (no, I don't know if that even works), which is why I keep coming back to that.

  3. Trolling for a reaction, lol. You think I'm here to troll people? Look at how long I have been here and how many posts I have; would a person with that history be trying to help you or be trying to fuck with you? I realize this sounds masturbatory and like I'm trying to toot my horn here to score internet points about how cool I am, but I am just trying to use it as evidence for why I wouldn't be trolling you.

  4. If you have some misconception about how loops or timing or projectiles work, I was hoping that I could clear those up rather than not addressing it and letting those misconceptions become problems for you later down the line. Just because a thread is marked as solved does not mean there is no discussion to be had; often an OP lacking knowledge about a topic will consider something solved without realizing a bigger/different/more-widespread problem underneath.
You're welcome not to respond to this; I won't bother you any more here.
 
Status
Not open for further replies.
Top