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

Math: Getting the time for missiles casted on moving units

Status
Not open for further replies.

Ardenian

A

Ardenian

Hello,

I am just average in math so I have problems solving this issue:

-> A unit casts a spell ( like Death Coil) to a moving object, like a unit that moves into a certain direction.

The aim: Making trigger damage hit as accurate as to the incoming missile model and special art.

My first thought: Simply, adding a 'Wait' with a timer 'Distance of casting unit to target / indexed speed of missile type'.

But, the unit the spell is casted on is moving, therefore this is too inaccurate.

In case the unit is there with an angle of 90°, it would be easy as I could use the Pythagoras, but there does not has to be a 90° angle.

So, how do I get the new ( rough estimated) distance, including the movement speed of the unit ?
 
Last edited by a moderator:

Ardenian

A

Ardenian

You need a DDS to detect when the damage is taken.

There is no 'damage' taken.
The damage is triggered, but I am not sure, does a spell dealing 0 damage is detected as damage hit ?

I need the wait timer to make the trigger damage as if it was dealt by the missile/spell.
 
Level 11
Joined
Jan 23, 2015
Messages
788
What you're trying to do is impossible, even if you measure everything you will fail to measure the distance when the projectile trajectory is curved, couse it will follow the unit while it moves.
A more simple way to solve this is to make a dummy unit with the model of the projectile and send it follow the player. You will check the distance between the dummy unit and the target every 0,03 sec and when it reaches zero(make sure the dummy has 0 collision) remove the dummy and do what you want.
If you find that complicated, you can add buff to the projectile spell and check every 0.03 sec if a unit has it.
 

Ardenian

A

Ardenian

What you're trying to do is impossible, even if you measure everything you will fail to measure the distance when the projectile trajectory is curved, couse it will follow the unit while it moves.
A more simple way to solve this is to make a dummy unit with the model of the projectile and send it follow the player. You will check the distance between the dummy unit and the target every 0,03 sec and when it reaches zero(make sure the dummy has 0 collision) remove the dummy and do what you want.
If you find that complicated, you can add buff to the projectile spell and check every 0.03 sec if a unit has it.

I don't think it is impossible if working with the rough estimated distance.

So basically its the question how I get the difference between the distance when the spell is casted and the distance the missile will have to cross considering the movement speed of the unit the spell is casted on.

The dummy solution sadly does not work as I have multiple units at the same time, not only one.

How do I add buffs to a spell ?
I sense this solution has its flaws, too. If the unit has a buff there will be a little buff symbol and I don't want to have to. I am not sure whether it is visible in a 0.03 time interval tho.
Also, I think multiple buffs are not possible, are they ?
 
Level 9
Joined
Apr 23, 2011
Messages
527
How do I add buffs to a spell ?
I sense this solution has its flaws, too. If the unit has a buff there will be a little buff symbol and I don't want to have to. I am not sure whether it is visible in a 0.03 time interval tho.
Also, I think multiple buffs are not possible, are they ?

a) in object editor
b) try removing the icon for the buff.
c) same buffs do not stack, if you apply different kinds of buffs to a unit, all will show up.
 

Ardenian

A

Ardenian

a) in object editor
b) try removing the icon for the buff.
c) same buffs do not stack, if you apply different kinds of buffs to a unit, all will show up.
Alright, I will try to, thank you!

So you want to somehow get the time the missile flew before hitting the target? Do you need it before the missile is launched?
Yes, I need the time from spell casted = missile shot up to spell hits / missile hits
Hm, the trigger that damages has the event 'A unit starts the effect of an ability' ( or whatever it is called in English), but the wait trigger can be added before the damage will be executed. So I don't need it before it is launched.
I think I need a variable that can be set to the wait timer before, as I use many different indexed projectiles and projectile speeds.

You will create a dummy for each target and issue it to follow, it's easier than you think.

Sounds a bit complicated, but how do I write the trigger then ?
Just a ITE with condition distance becomes = or ~ 0 ?
I don't really know how to write the trigger, what event would it use ?
 
Level 9
Joined
Apr 23, 2011
Messages
527
when the spell is casted, make a dummy and order it to move to position of caster using a loop, also checking if the projectile dummy is near the unit. if it is, kill the projectile and deal damage. so yeah, use an ITE for the distance check.

do note that you can't make movespeed more than 522 unless you use a system for that or you move the dummy using triggers.
 

Ardenian

A

Ardenian

when the spell is casted, make a dummy and order it to move to position of caster using a loop, also checking if the projectile dummy is near the unit. if it is, kill the projectile and deal damage. so yeah, use an ITE for the distance check.

do note that you can't make movespeed more than 522 unless you use a system for that or you move the dummy using triggers.

Alright, thank you, I will try to write it based on your steps.
 
Level 11
Joined
Jan 23, 2015
Messages
788
Hmm, then you need the dummies to attack the targets, give them some ability based on dryad's poison ability or smth similar with the desired projectile and 0.04 sec duration. you will check if a unit has that buff every 0.03 sec. If you don't want to see the icon of the buff delete it.

when the spell is casted, make a dummy and order it to move to position of caster using a loop, also checking if the projectile dummy is near the unit. if it is, kill the projectile and deal damage. so yeah, use an ITE for the distance check.

do note that you can't make movespeed more than 522 unless you use a system for that or you move the dummy using triggers.

That's exactly what I planned it to be, but the number of targets is infinite and if there's like 10 targets how can you measure the distance between them and the dummies?
 

Ardenian

A

Ardenian

Hmm, then you need the dummies to attack the targets, give them some ability based on dryad's poison ability or smth similar with the desired projectile and 0.04 sec duration. you will check if a unit has that buff every 0.03 sec. If you don't want to see the icon of the buff delete it.

Okay, I think I will manage it somehow, thank you.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
when the spell is casted, make a dummy and order it to move to position of caster using a loop, also checking if the projectile dummy is near the unit. if it is, kill the projectile and deal damage. so yeah, use an ITE for the distance check.

do note that you can't make movespeed more than 522 unless you use a system for that or you move the dummy using triggers.

By using a missile system, it is possible to have more than 522 speed. Instead of ordering it to move, you can take the angle between missile and target and move the target's location offset by the angle between them.
 
Level 25
Joined
Sep 26, 2009
Messages
2,384
@Ardenian
What you want to achieve (calculating time with wait) is not possible, because you don't have a static target but a moving one.

First of all, using wait in this case - where you want to get accurate "on hit" event, is bad idea by itself, as waits are inaccurate. They're never the time you set them.

Now, to the problem with moving target. That problem isn't that bad by itself if the target moved linearly, however he can change direction and speed at any given time. That makes your approach impossible. An example of speed increase is for example a Warden using Blink ability.

So the idea to solve this is to either damage the unit with already existing spell (e.g. firebolt), however this does have its drawbacks in forms of debuffs. The other option is to create a dummy unit with the model of the projectile itself, move it yourself and detect the distance between the dummy and target. If the dummy is close enough, then you "hit" the target.

I would do it via dummy personally, because it gives you more option and if set correctly has practically no drawbacks.
The dummy movement Light wrote about is not a good approach, though. The reason is because units don't move directly to the location you order them to. The other reason is the maximum speed of 522.
What you can use are the functions "SetUnitX" and "SetUnitY" which move unit to the X and Y coordinates. Both X and Y coordinates can be read from any location you have in point variable. The idea here is that you move said unit every 0.03 seconds bit by bit towards the target.
This allows you to move units directly to the target. Here is a tutorial which explains how those two functions work: http://www.hiveworkshop.com/forums/miscellaneous-tutorials-456/about-movement-172309/
 

Ardenian

A

Ardenian

@Nichilus
Thank you, it seems I cannot avoid a missile system.
A missile system basically does the thing you describe, doesn't it ?

I wanted to avoid having it to import as I failed badly to do so..
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Download a missile system.
There are plenty systems that do what you want and they catch all problematic stuff as well.

There is also a way to do this using a unit indexer and damage detection system (without checking for buffs) but that is much more work than using a missile system.

I have one of my own but you probably do not want to use any of the unique features that it has :D
 

Ardenian

A

Ardenian

I have one of my own but you probably do not want to use any of the unique features that it has :D
Thank you for making me aware of another solution!

Yeah, I noticed yours has a lot of features, so many features that I lost the view on what's the trigger I need.
I thought it is the firebolt, but CnPing it into my map crushes triggers and deactivates them all.
I am so bad with advanced triggers, I will have to ask someone for implementation...
 

Ardenian

A

Ardenian

Then you havent got automatic GUI variables enabled.
Go to: Terrain Editor -> File -> Preferences... and check "Automatically create unknown variables while pasting trigger data"
That should do the trick.

No, it is activated :/ I don't know why, maybe I didn't CnP all necessary data or the system cannot be used with the default WE or whatsoever.
A I said, I am very bad with implanting systems and such.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I did write down a little bit about how to import it.
When you copy and paste the system's folder first, all should be fine.

Ow yea and you need some object editor data.
Just look in the trigger "CMS System" and find "How to import" in the green text at the top.
 

Ardenian

A

Ardenian

I did write down a little bit about how to import it.
When you copy and paste the system's folder first, all should be fine.

Ow yea and you need some object editor data.
Just look in the trigger "CMS System" and find "How to import" in the green text at the top.

Oh, I think I missed this, thank you, I will try again!
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
The ability should do damage if it is based on death coil on an enemy. On an ally you are right as healing is not damage. You could try using a target ability that does do damage instead such as chain lightning (which does fire a missile as well as a lightning I recall). Then a DDS should pickup the missile impact as an event.

As for computing impact time for homing missiles there is no truly accurate way. The best could be done by simulating the missile movement and adjusting for unit movement. For example every 0.1 seconds you could check if the missile has hit the unit in its current position and if not advance it towards the unit. This is resource intensive but should be fairly accurate (the missile should at least be nearby or hit very recently when it fires an impact).

A less accurate approach would be to do a rough estimation based on the units current movement speed and direction. You sample the unit 0.1 seconds after the launch and use its velocity to compute an impact time. This will likely need some pretty advanced maths (integrals/differentials etc) to get the appropriate formula. This will work if the target stays on course and be fairly accurate as long as the missile moves fast. It will be very inaccurate if the unit inverts velocity or the missile is slow enough to dodge.
 

Ardenian

A

Ardenian

The ability should do damage if it is based on death coil on an enemy. On an ally you are right as healing is not damage. You could try using a target ability that does do damage instead such as chain lightning (which does fire a missile as well as a lightning I recall). Then a DDS should pickup the missile impact as an event.

As for computing impact time for homing missiles there is no truly accurate way. The best could be done by simulating the missile movement and adjusting for unit movement. For example every 0.1 seconds you could check if the missile has hit the unit in its current position and if not advance it towards the unit. This is resource intensive but should be fairly accurate (the missile should at least be nearby or hit very recently when it fires an impact).

A less accurate approach would be to do a rough estimation based on the units current movement speed and direction. You sample the unit 0.1 seconds after the launch and use its velocity to compute an impact time. This will likely need some pretty advanced maths (integrals/differentials etc) to get the appropriate formula. This will work if the target stays on course and be fairly accurate as long as the missile moves fast. It will be very inaccurate if the unit inverts velocity or the missile is slow enough to dodge.

Thank you very much for this detailed examples!

I will see which way will be the best ( for me to executable).
 
Status
Not open for further replies.
Top