• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Can somene please fix my triggers ?

Status
Not open for further replies.
Level 17
Joined
Jul 1, 2010
Messages
720
I tried recreating a caravan system like in the campaigns and I had fairly good success, problem is I'm bad at math and although I did manage to make them move in a formation, the caravan units don't orient themselves towards the next checkpoint. I want the caravan units to be treated as one formation, front guards stay in front no matter the orientation, middle stay in the middle, back in the back etc.... Check the map file and you'll know what I mean.

View attachment WorldEditTestMap.w3x
 
Level 29
Joined
Sep 26, 2009
Messages
2,596
First things first - remove the memory leaks if this is supposed to be "the final version"

The problem is obviously in the moment you send your squad on the move with the "move" command.
You calculate the target point for the guard incorrectly. Your angle calculation is:
"Angle r = angle between current_caravan_position and current_guard_position"
What you need to do is also calculate the difference between the direction from last_point to current_point and direction from current_point to next_point. Then subtract the difference for each guard.
So basically:
Difference between those two angle is "d"
So your final offset is "(Angle between caravan and guard) - d". Do note that it is important what you subtract!
The result is different if you do "Angle A - Angle B" and "Angle B - Angle A".


Try the attached test map. Just ignore the memory leaks there. Right now the offset (and turn angle) is set to 30 degrees. Just change the value of "TURN_ANGLE" variable to your desired angle. Ingame press ESC key to fire the trigger.
Do note that the unit is turning way slower than needed, so don't spam the ESC key - if you do and the unit won't have enough time to turn, it will seem to bug out (but in reality still work as intended).
 

Attachments

  • CaravanOffset.w3x
    16.4 KB · Views: 34
Level 17
Joined
Jul 1, 2010
Messages
720
Well that's what I need, to figure out the turn angle towards the next checkpoint while staying in formation, I told you I'm bad at math, how do I find the turn angle in my map ? yours is fixed, it's 30 but I don't have it. Did you look over my map ?
I want the units to stay in formation but to face the point as a whole, think of it as a box, the units are a box, e.g. the spell breakers remain in front, archers middle...i don't know if you understand me
 
Level 29
Joined
Sep 26, 2009
Messages
2,596
Yes, I put 30 just so you know the turn angle. That way you know where the guard should be positioned.

In your case you need this:
For the starting position (the very first where you spawn your cargo and guards) you have no "previous direction" so just manually save into some variable their facing angle.
But then for each point you go to you do this:
  • Actions
    • -------- Note: Here you already have some value in PreviousAngle --------
    • -------- --------------------------------- --------
    • Set NewAngle = (Angle from current_point to next_point)
    • Set Difference = (PreviousAngle - NewAngle)
    • -------- --------------------------------- --------
    • -------- Save the current NewAngle as the PreviousAngle for the next movement --------
    • Set PreviousAngle = NewAngle
The rest is like I did in the map I posted in my previous post.
(in case this does not produce the correct result, try changing the order from "PreviousAngle - NewAngle" to "NewAngle - PreviousAngle")

Also, I cannot test it right now, but also write via Game Message the NewAngle you got. I'm not sure if "Angle between points" degrees go from [-180, 180] instead of [0, 360].
 
Status
Not open for further replies.
Top