Jump to content

[LE] Help with Troop Formations


Recommended Posts

So I've been trying to figure out how to create formations for groups of soldiers. The only two mods I have found that do this are: Mixed Unit Tactics and Mercenaries, the former of which does not include source code. It seems like the latter uses some kind of system which calculates some sort of coordinates that tell the followers where to move to, but I am looking at the creation kit scripting references website and can't find any source as to which function I can use to order an NPC to move to a certain coordinate/location, other than moveto(), which teleports the NPC to the location rather than telling them where to actually move to.

Link to comment
Share on other sites

KeepOffsetFromActor it is what I used to get the follower to walk beside the player in Followers as Companions.

ClearOffsetFromActor will be needed to get your NPCs to break formation for whatever reason.

 

To see how the one that did not include source code did it, you can use Champollion to decompile the PEX files into a readable and reusable format (tho it won't look the same as the original)

Link to comment
Share on other sites

So I was successful in getting the soldiers to assume proper battle formations as we see here:

https://streamable.com/dwy12k

 

 

For testing purposes and a first step, I created several actor properties and assigned each one to a position.

 

However, I know that once certain NPCs die, their position/role in the formation would be empty and not filled. I am curious as to how to make it so that if X soldier dies in XYZ position, a nearby soldier could take his position. I am assuming that in order to do this, I need to create ReferenceAlias proprties rather than actors, and find a way so that when an actor dies, a new actor will replace that same Reference Alias?

Edited by Guest
Link to comment
Share on other sites

Probably do need to use reference aliases.

 

I'm wondering if it would be possible to have something like LeadA, LeadB, LeadD and LeadE each at an offset from the player / commander (who would be LeadC). For those that follow, give them a modified variation of the follower package and have them follow a specific lead. Thus any gaps in the following ranks would auto-fill as replacements are added. Only the leads would then need to be specifically replaced.

Link to comment
Share on other sites

That sounds like a good idea, will look into it.

 

Also, I was wondering if there was a way to fix the NPCs that are running backwards with this function on. It seems that if the player faces and moves a certain direction, all the troops seem to run backwards which makes everything awkward and slows them down.

Link to comment
Share on other sites

It seems like the afOffsetAngleZ variable dictates the rotational speed of the actor, and not where the actor wants to actual rotate to.

 

I am looking at the function as a first step:

 

TranslateTo

Function TranslateTo(float afX, float afY, float afZ, float afAngleX, float afAngleY, float afAngleZ, float afSpeed, \
float afMaxRotationSpeed = 0.0) native

 

 

However, I am only interested in setting the Z rotation values and rotational speed of these actors attached to the formation and no other values. I am a bit confused as to how to enter the parameters for these functions when I want to execute these functions in my script.

 

EDIT: It looks like this function is bad, it causes actors to run in place. It's probably just for static objects. Guess I got to stick with doing some math to figure out conditions on how to rotate these actors in the afOffsetAngleZ variable.

Edited by Guest
Link to comment
Share on other sites

I've tried ClearLookAt, and the actors will look at the assigned NPC if in their sight, but not actually physically rotate their bodies. Right now it seems like the solution is to look at the afOffsetAngleZ variable, which sets the rotational speed of the NPCs. From my testing it seems that when afOffsetAngleZ = 0, the actors won't bother fully rotating at all under normal circumstances until their formation breaks. However, when afOffsetAngleZ > 0, the NPCs in formation begin to rotate their bodies regardless of path or location, with a higher value (ie. 100) making the NPC rotate faster than with a low value (1-5).

 

I am currently trying to figure out a way that makes it so that this variable (afOffsetAngleZ) will change based on the conditions of the NPC related to the Player, relating to the Z-angles.

So if the difference between the NPC's angle and the Player's angle is high enough (like when the NPC and Player are facing opposite directions), the afOffsetAngleZ variable could be set to be something high like 20 which would make the NPC rotate. Then when the NPC's angle is relatively close compared to Player's angle (say player is at Z=22 and NPC Z=10), the afOffsetAngleZ = 0 to stop them from rotating. There would be an event that constantly checks to make sure they rotate or stop rotating only when conditions are met.

 

The tricky part for me is figuring out how to do all the math with all the angles, since I am not sure how the game calculates angles when you subtract the value to an angle that is higher than its original value (ie. 180 degrees - 280 degrees would = -100 degrees, or 260 degrees...which one is the game going to calculate and decide).

 

Also how to make functions that are efficient so I am not repeating the same code over and over for different NPCs. Perhaps a bool that tells whether NPC is facing Target Actor or not that we can use to determine when the actor should rotate or when they shouldn't.

 

 

This is literally the last step in making functional shield walls and formations a reality, NPCs will fight in formation correctly AS LONG AS they are facing the NPC, which means a line of shields not facing the same directions unison means some NPCs won't engage at all. I'll see what I can get tonight.

Edited by Guest
Link to comment
Share on other sites

Figured it out. It takes tons of intense math, logic, knowledge of geometry, and persistence, but like I mentioned before it comes down to adjusting the variable afOffsetAngleZ with formulas based on another's actors current angle, and a lot of checking and updating to see whether the squad is out of position or not. I will share some code once I make some further tweaks.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...