Wurst Missile System

Discussion in 'The Lab' started by Lake, Feb 3, 2019.

Tags:
1. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
Right, I might have said something wrong here. I agree with this:

The flight path should indeed be set when given those parameters - that's the idea The difference from your system to this, is that this takes the firing angle as a parameter instead of gravity.

Why I need the vertical velocity is for calculations purposes. And knowing the firing angle, the horizontal distance and velocity, I should be able to calculate it.

2. GuineapigRoast

Joined:
Jan 31, 2019
Messages:
27
Resources:
0
Resources:
0
If you know the angle and either the horizontal velocity or the total firing velocity, you get the vertical speed by:

Vertical launch speed = tan(angle) * horizontal launch speed

or

Vertical launch speed = sin(angle) * total launch speed

However, if you have a given firing velocity, your projectile might not even be able to reach a point that you want to reach. Also you cannot give firing angle, total distance to target and horizontal speed as parameters, since two of those being given means the third one is a given as well.

3. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
That's exactly what I want I have tried this:

... But I can't seem to get it to work - probably something wrong with my other calculations. Have to try and find a fix for that.

4. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
But it sure does create a nice arc, and is muuuuuch simpler than the solution I had to begin with, so this is really nice!

5. GuineapigRoast

Joined:
Jan 31, 2019
Messages:
27
Resources:
0
Resources:
0
I might be able to help if you if you share your code. Basically if you want your missiles to work so that they always launch at a constant total velocity, but at a different launch angle, you have to calculate the required launch angle like this:

Source: Projectile motion - Wikipedia

6. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
Alright, scratch what I've said - I have to bite the dust here. The pieces fall into place now. I see what you mean, that if I have a set horizontal speed and angle, the vertical speed will only have one possible outcome. Aaand the only way to adjust the distance, is to adjust the gravity (sorry for taking so long - just had to see it in practice).
And of course, I can still make it the way I want, such that I give those parameters, but what I have to worry about is not as much the vertical velocity as the gravity. So I have to calculate the appropriate gravity in order for it to go the distance that I want Enlightnement ftw

7. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
My Git repo is here: maltebp/MissileSystem

8. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
This also makes me realize propably how they calculate the firing angle for with original wc3 projectiles. The "arc" setting probably sets the relation between the x-velocity and the y-velocity, such the the VelY = VelX * arc * someArcConstant (someArcConstant seems like its 2). Thus it will never be able to exceed a firing angle that is directly upwards nor negative or backwards. It also explains why the missiles go so fast when you set the arc to something high, like 5.

9. GuineapigRoast

Joined:
Jan 31, 2019
Messages:
27
Resources:
0
Resources:
0
If you increase arc, does it take a longer time to hit the target even when distance stays the same?
If it stays the same, it probably works similarly to my system where the horizontal speed stays the same, and only vertical speed is increased (and the gravity, since otherwise increasing the vertical speed would increase distance).
If the time to hit target changes, the arc value is probably the value of tan(angle) and the vertical and horizontal speeds are just calculated with that ange, and then the gravity is reduced to a point where the projectile flies long enough to reach the desired distance.

10. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
From what I've found the projectile speed is the horizontal speed, so exactly the same as yours

11. GuineapigRoast

Joined:
Jan 31, 2019
Messages:
27
Resources:
0
Resources:
0
Allright, in that case, if you want to modify my class to use an arc constant like WC3, you just replace the gravity parameter with an arc parameter that accepts values between 0-0.9999, calculate tan(arc * pi/2) * horizontal speed to get vertical speed, and then solve for gravity required to have the appropriate height after time = distance / horizontal speed

Code (Text):

gravity = (2 / time) * (heightDifference / time - verticalSpeed)

Last edited: Feb 7, 2019
12. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
Hehe, now I'm too curious, so I'm continuing with my own now

Trying to make use of the formular though, as mine didn't work exactly. But seemed like this didn't help. Apparently, when calculating the gravity with a height difference, the missile doesn't hit the exact spot. The deviation is larger the closer the targetpos is to origin position. Have a theory it has something to do with decimal numbers getting too low, and some data is lost

13. GuineapigRoast

Joined:
Jan 31, 2019
Messages:
27
Resources:
0
Resources:
0
Im pretty confident my formula should work. Push your code and we can take a look.

14. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
It works like a charm, when you keep recalculating the gravity for every update But when you only do it when you fire the missile, it's a little bit inaccurate - but so was my own. If it could work, it would be a little bit of an optimization, since you'd get rid of a whole lot of calculations.

I've pushed it (check the development branch).

15. GuineapigRoast

Joined:
Jan 31, 2019
Messages:
27
Resources:
0
Resources:
0
Im not sure if it will affect the accuracy or anything, but just a few comments:
- originPos.angleTo2d(targetPos) returns an angle for which you can already call trigonometric functions such as .cos()
- I believe ANIMATION_PERIOD is the shortest interval you can have on timers, not 0.01. Not sure what happens if you enter 0.01 anyway.
- You can use closures ( doPeriodically() ) to run the updateloop. No need for timers and adding data to them etc.

16. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
Probably won't affect accuracy, but definitely are nice improvements! Saw them in your code as well, and it makes a lot of sense
I think that for now I'll just make use of the same technique as you, by recalculating the update. Can always optimize the backend anyway, as long as the frontend parameters stays the sme.

Last edited: Feb 7, 2019

Wurst Reviewer

Joined:
Jan 1, 2009
Messages:
1,479
Resources:
11
Models:
3
Tools:
1
Maps:
5
Tutorials:
1
Wurst:
1
Resources:
11
Weird that Watsuby only linked gold rush, actually all my maps contain missiles of some sort, based on Frentity. e.g. Frotty/Snowball-Fight

It's not lowest for timers, it's a threshold of when SetUnitPosition will cause a unit to be unable to move, e.g. used for ice sliding.
With 1/32 it will not, with 1/33 or 0.03 in this case it will.
Also in general it seems to be a good value for smooth movement, hence animation.
Collision checks are usually fine with higher values, I'm using 0.06, so roughly 16 checks per second, which is totally fine if you don't have high speed, small, bullet-like missiles or very thin walls.

Since you are iterating over all objects of a class, the TimedLoop module should be even nicer to use as it's made for that purpose.

18. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
Awesome, even more stuff to get draw inspiration from! Thanks for your feedback! Haven't been at it for a while now, as I've been busy lately, but getting back to work now. And neat little tricks! I have indeed been using timers with frequencies below the animation period, but that was primarily because I didn't know the exact time to generate a smooth movement.

That TimedLoop is pretty neat as well. Actually implemented somthing similar myself (abstract Updater class), but that was before I knew this is existed! Will indeed just make use of this instead

I'm toying with the idea of making a simple version of the missile where the on-hit-action would be saved as a lambda function, instead of having to implement an abstract missile class. Not sure if it makes any sense to do in this way, but nonetheless I'll give it a shot.

Wurst Reviewer

Joined:
Jan 1, 2009
Messages:
1,479
Resources:
11
Models:
3
Tools:
1
Maps:
5
Tutorials:
1
Wurst:
1
Resources:
11
You're very welcome! Spread the love

Yes, it is very reasonable. The generated code is basically the same - the dispatch just changes location.
Mostly depends on taste - in my case I started using wurst from the start - before it had closures etc. so especially my old maps have a wide mix of different practices.
@Cokemonkey11 's maps heavily use closures in many places.

Cheers

20. Lake

Joined:
Mar 5, 2015
Messages:
135
Resources:
0
Resources:
0
Good to hear that I'm not completely lost I'll try and see where it leads, and I'll probably request some feedback on the finished system here on Hive so that it may be interesting for others to use as well.

Of course, I take feedback all the time as the system progress on GitHub

Last edited: Feb 24, 2019