While working on SKS, I’m running into a few situations where jumping the party around for cutscene-like events is resulting in characters being on top of each other. I started looking at a library script to better position the party.
Ideally, I’d like all henchmen, follower, companions and other PCs to be lined up in rows of three behind the first PC. This lead me down the path of some facing and vector math that I’m finding to be a bit of a stretch.
The goal is for the function to get the facing of the waypoint we are jumping to and base everything on that. I’m wondering if there’s a better way to do this. I’m also wondering if someone who is better at vectors and facing math has any suggestions.
Also, I’m pretty sure my modulus is off on the first run and needs adjusting.
void SKS_JumpPartyToLocation(object oPC, object oTarget)
{
SKS_Debug("---starting SKS_JumpPartyToLocation---");
float fXIncrement = 1.0;
float fYIncrement = 1.0;
// Get the vector of our target
object oArea = GetArea(oTarget);
vector vStart = GetPosition(oTarget);
float fTargetFacing = GetFacing(oTarget);
SKS_Debug(VectorToString(vStart));
// Create variables to track our offsets
float fXOffset = 0.0;
float fYOffset = 0.0;
int nJumpCount = 0;
float fYAdjusted = 0.0;
float fXAdjusted = 0.0;
// Loop through all party members
object oPartyMember = GetFirstFactionMember(oPC, FALSE);
while(GetIsObjectValid(oPartyMember)){
// PC only, fades and camera
if (GetIsPC(oPartyMember))
{
// Fade to black
DelayCommand(0.2, FadeToBlack(oPartyMember, FADE_SPEED_FAST));
// Adjust the camera
DelayCommand(1.2, AssignCommand(oPartyMember, SetCameraFacing(fTargetFacing)));
// Fade out of black
DelayCommand(3.5, FadeFromBlack(oPartyMember, FADE_SPEED_MEDIUM));
}
// Clear actions
DelayCommand(0.1, AssignCommand(oPartyMember, ClearAllActions()));
// Jump to the new location
vector vOffset = Vector(fXOffset, fYOffset);
vector vEndvector = vStart+vOffset;
SKS_Debug("jumping: " + VectorToString(vEndvector));
location lFinalTarget = Location(oArea, vEndvector, 0.0);
DelayCommand(1.0, AssignCommand(oPartyMember, ActionJumpToLocation(lFinalTarget)));
DelayCommand(1.1, AssignCommand(oPartyMember, SetFacing(fTargetFacing)));
// Get next party member
oPartyMember = GetNextFactionMember(oPC, FALSE);
// Adjustt values for the next run
if (nJumpCount == 0 || nJumpCount % 3 == 0)
{
fXAdjusted = fXAdjusted + fXIncrement;
fYAdjusted = fXIncrement * -1;
SKS_Debug("modulus: x "+ FloatToString(fXAdjusted) +" y "+ FloatToString(fYAdjusted) +".");
}
else {
fYAdjusted = fYAdjusted + fXIncrement;
SKS_Debug("else: x "+ FloatToString(fXAdjusted) +" y "+ FloatToString(fYAdjusted) +".");
}
nJumpCount++;
// Adjust the location for the next loop
// See https://math.stackexchange.com/questions/143932/calculate-point-given-x-y-angle-and-distance
fXOffset = fXAdjusted * cos(fTargetFacing);
fYOffset = fYAdjusted * sin(fTargetFacing);
SKS_Debug("final offest values are: x "+ FloatToString(fXOffset) +" y "+ FloatToString(fYOffset) +".");
}
}
Thanks in advance for any suggestions!