• 🏆 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] Making unit move towards point with polar offset

Status
Not open for further replies.
Level 8
Joined
Feb 17, 2018
Messages
114
So, I've made a spell based on channel with point-target. The idea of the spell is that it creates a dummy with locusts and this dummy must go into target point of abillity beign cast direction untill it reaches the edge of playable map area and dies after. But the problem is that unit goes only 0, 45, 90, 135, 180, 225, 270, 315 degrees. My researched showed that if I shorten an offset range the unit will go the right direction but won't go trought the entire map (I think this is connected with the map size (changing map size won't help)). In short: i need unit to go the direction of target point of ability being cast till it reaches the end of the map. Here are the triggers:
  • Scout
    • Events
      • Unit - A unit starts an effect of ability
    • Conditions
      • (Ability being cast) equals Ð Scout
    • Actions
      • Unit - Create 1 Scout for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing (Target point of ability being cast)
      • Set aa_TempPoint = (Position of (Last created unit))
      • Set aa_TempPoint2 = (aa_TempPoint offset by 15000.00 towards (Facing of (Last created unit)) degrees)
      • Unit - Order (Last created unit) to move aa_TempPoint2
      • Custom script: call RemoveLocation(udg_aa_TempPoint)
      • Custom script: call RemoveLocation(udg_aa_TempPoint2)
  • RemoveScout
    • Events
      • Unit - A unit leaves (Playable map area)
    • Conditions
      • (Unit-type of (Triggering unit)) equals Scout
    • Actions
      • Unit - Remove (Triggering unit) from the game
 
Level 12
Joined
Jun 15, 2016
Messages
472
I think the best, safest way to achieve that is to create trigger which will fire periodically and order the scout to move a little bit forward (or move the scout itself directly). The downside is the added complication of keeping track of everything. You can see method to periodically work with multiple scouts in this tutorial Visualize: Dynamic Indexing .

Another way is to calculate aa_TempPoint2 rather than assigning it to just some distance. For example, you can do the following:

1. Calculate the angle from the caster to each map corner (map corners as in North East, North West, South East, South West), and compare those to the caster's facing angle. That way you will find which side your scout will reach.
2. You now have a right triangle where you want to find the hypotenuse, and you have the length of the triangle side next to it and the angle between them. In short, you can calculate the distance between the caster and the side your scout will reach by simple subtraction, and divide that number by the sine of the facing angle (after making it in the range of 0-90 degrees).

This way you can find a safe offset distance to assign aa_TempPoint2.
 
Level 8
Joined
Feb 17, 2018
Messages
114
I think the best, safest way to achieve that is to create trigger which will fire periodically and order the scout to move a little bit forward (or move the scout itself directly). The downside is the added complication of keeping track of everything. You can see method to periodically work with multiple scouts in this tutorial Visualize: Dynamic Indexing .

Another way is to calculate aa_TempPoint2 rather than assigning it to just some distance. For example, you can do the following:

1. Calculate the angle from the caster to each map corner (map corners as in North East, North West, South East, South West), and compare those to the caster's facing angle. That way you will find which side your scout will reach.
2. You now have a right triangle where you want to find the hypotenuse, and you have the length of the triangle side next to it and the angle between them. In short, you can calculate the distance between the caster and the side your scout will reach by simple subtraction, and divide that number by the sine of the facing angle (after making it in the range of 0-90 degrees).

This way you can find a safe offset distance to assign aa_TempPoint2.
This seems (Another way) really intresting. But I really have no clue how to do this.
 
There is a move unit function available in GUI.

  • Unit - Move (unit) immediately towards (point offset), ...
If you want to skip safety checks in pathing, you can use these natives in Custom Script:

JASS:
SetUnitX(unit, real)
SetUnitY(unit, real)

Or, for convenience:

JASS:
// Move this to map header.
function SetUnitXY takes unit u, real x, real y returns nothing
    call SetUnitX(u, x)
    call SetUnitY(u, y)
endfunction
 
Level 12
Joined
Jun 15, 2016
Messages
472
I got bored and created a demo map for the second method. If the suits you I can do some minor fixes to make it usable.

When in the map, press Esc and a sentinal owl will spawn on the edge of the map where the archmage is facing. It should work everywhere except the edges of the map, but that's no big problem.
 

Attachments

  • Offset example.w3m
    18.3 KB · Views: 49
Level 8
Joined
Feb 17, 2018
Messages
114
I got bored and created a demo map for the second method. If the suits you I can do some minor fixes to make it usable.

When in the map, press Esc and a sentinal owl will spawn on the edge of the map where the archmage is facing. It should work everywhere except the edges of the map, but that's no big problem.
That would be very nice of you. The proble is that I'm really not much in Jass.
 
Level 9
Joined
Apr 23, 2011
Messages
527
If you really want to use GUI:
This assumes that the unit-type created is unique to that ability.

- When the ability is cast, add the Scout unit to a unit group (make sure it faces the target point)
- In another trigger, every 0.03 seconds pick every unit in the unit group and do:
* Set the position and facing of a unit to variables
* Move the unit towards the facing by, say, 50 units
* Clear the leaks
This way, each unit will move in separate directions based on its original facing.

Don't know how I'd do removing the unit, maybe remove the unit if it exits playable map area?
 
Level 12
Joined
Jun 15, 2016
Messages
472
That would be very nice of you. The proble is that I'm really not much in Jass.

I would actually suggest you use the method @Light suggested, as it is more foolproof, more like what people usually do around here, and less likely to cause problems. So for convenience I'll repeat what light offered:

1. Create a scout at/near caster's location.
2. Start a timer which will expire every 0.03 seconds, and move the scout unit a small X distance every time the timer expires.
3. Once the scout unit is closer to the map edge or just went over the map edge, remove it (and d whatever you need to for when the spell is done).

If you are new to triggering, try making that one thing work.

If you are familiar a bit with triggering you would notice there is a problem - this trigger is not MUI (multi unit instantiable). This is where dynamic indexing comes in (that's the tutorial from my first post here). Read it and see how to adjust your trigger.
 
Level 9
Joined
Apr 23, 2011
Messages
527
If you are familiar a bit with triggering you would notice there is a problem - this trigger is not MUI (multi unit instantiable). This is where dynamic indexing comes in (that's the tutorial from my first post here). Read it and see how to adjust your trigger.

A solution I offered to make it MUI was to add the scout units to a unit group as they are being created, and picking all of the units in that unit group and moving them accordingly.

I am just afraid that periodic event can cause performance issues. Aslo I wanted unit to go on its own. But I think I'll stick to periodic for now. Thanks for help anyway.

No, periodic events of low duration do not usually cause performance issues unless there are a ton of things being done.
 
Status
Not open for further replies.
Top