61 ref array<ref Shape> m_aDbgShapes = {};
71 m_UtilityComponent = SCR_AIUtilityComponent.Cast(owner.FindComponent(SCR_AIUtilityComponent));
83 return physics.GetVelocity();
94 muzzlePos = muzzleMat[3];
95 muzzleDir = muzzleMat[2];
98 vector futureTargetPos = targetPos;
99 targetDistance =
vector.Distance(muzzlePos, futureTargetPos);
105 for (
int i = 0; i < iterations; i++)
107 rangeOffset =
BallisticTable.GetAimHeightOfNextProjectile(targetDistance, predictionTime, currentMuzzle);
108 futureTargetPos = targetPos + (targetVelocity * predictionTime);
109 targetDistance =
vector.Distance(muzzlePos, futureTargetPos);
121 muzzleDir = shooterMat[2];
124 vector futureTargetPos = targetPos;
125 targetDistance =
vector.Distance(muzzlePos, futureTargetPos);
131 for (
int i = 0; i < iterations; i++)
133 rangeOffset =
BallisticTable.GetHeightFromProjectile(targetDistance, predictionTime, entity, initSpeedCoef);
134 futureTargetPos = targetPos + (targetVelocity * predictionTime);
135 targetDistance =
vector.Distance(muzzlePos, futureTargetPos);
146 if (!character || !character.IsInVehicle())
149 CompartmentAccessComponent compAccComp = character.GetCompartmentAccessComponent();
153 IEntity vehicle = compAccComp.GetVehicleIn(character);
168 float targetElev = targetPos[1] - world.GetSurfaceY(targetPos[0], targetPos[2]);
174 float aimPosSurfY = world.GetSurfaceY(aimPos[0], aimPos[2]);
175 float aimPosElev = aimPos[1] - aimPosSurfY;
179 aimCorrectionVector[1] = aimCorrectionVector[1] - (aimPosElev * 0.85);
182 float surfYDiff = targetElev - aimPosElev;
185 float confidence =
Math.Clamp(
Math.Map(speedMs, 3, 32, 1, 0.7), 0.2, 1);
186 surfYDiff *= confidence;
189 float predSurfYDiff = (aimPos[1] + aimCorrectionVector[1] + surfYDiff) - aimPosSurfY;
190 if (predSurfYDiff < 0.1)
191 surfYDiff +=
Math.AbsFloat(predSurfYDiff - 0.1);
193 aimCorrectionVector[1] = aimCorrectionVector[1] + surfYDiff;
201 float targetDistance, predictionTime, rangeOffset;
202 vector muzzlePos, muzzleDir;
204 if (currentWeapon && currentMuzzle)
205 rangeOffset =
GetMuzzleAimData(currentMuzzle, targetPos, targetVelocity, 2, targetDistance, predictionTime, muzzlePos, muzzleDir);
206 else if (currentWeapon)
230 if (fixedAimPoint ==
vector.Zero)
233 float aimPointTargetDist =
vector.Distance(targetPos, fixedAimPoint);
237 fixedAimPoint =
vector.Zero;
259 distanceFactor = 0.0006;
267 vector aimPos = targetPos + aimVector;
268 vector dirToAimPoint =
vector.Direction(muzzlePos, aimPos).Normalized();
269 vector dirToTarget =
vector.Direction(muzzlePos, targetPos).Normalized();
271 float angleFactor, distanceFactor;
274 float angle =
Math.Acos(
vector.Dot(dirToTarget, dirToAimPoint));
275 float angleTime = angle * angleFactor;
276 float distanceTime = targetDistance * distanceFactor;
283 float correctionTime = angleTime + distanceTime;
286 vector aimCorrectionVector = targetVelocity * correctionTime;
289 CorrectForSurface(aimCorrectionVector, targetPos, aimPos, targetVelocity.Length(), targetDistance);
291 return aimCorrectionVector;
300 float time =
GetGame().GetWorld().GetWorldTime();
304 float initSpeedCoef = 1.0;
315 Print(
"GetAimCompensation: provided null entity",
LogLevel.WARNING);
325 Print(
"GetAimCompensation: provided null aimpoint",
LogLevel.WARNING);
329 targetPos = aimPoint.GetPosition();
376 currentMuzzle = currentWeapon.GetCurrentMuzzle();
383 vector muzzlePos, muzzleDir;
384 float targetDistance, rangeOffset, predictionTime;
385 float relativeAbsSpeed =
Math.AbsFloat((targetVelocity - shooterVelocity).Length());
419 if (currentWeapon && currentMuzzle)
420 rangeOffset =
GetMuzzleAimData(currentMuzzle, targetPos, targetVelocity, iterations, targetDistance, predictionTime, muzzlePos, muzzleDir);
421 else if (currentWeapon)
428 if (suppression > 0.01)
429 predictionTime += predictionTime * (suppression -
Math.RandomFloat(0, suppression * 2));
432 vector aimCorrectionVector;
436 aimVector -= (shooterVelocity * predictionTime);
444 aimVector += (targetVelocity * (predictionTime + 0.5*dt));
453 aimVector[1] = aimVector[1] + rangeOffset;
457 m_aDbgShapes.Clear();
484 protected override static string GetOnHoverDescription() {
return "Returns offset for compensation of target range and velocity. Offset will be added to VectorIn, so it can be used for build-in imprecision.";}
ArmaReforgerScripted GetGame()
proto external vector GetOrigin()
proto external Physics GetPhysics()
proto external void GetTransform(out vector mat[])
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
static float FIXED_AIM_POINT_TIMEOUT_FACTOR
vector GetEntityVelocity(IEntity entity)
float GetEntityAimData(IEntity entity, float initSpeedCoef, vector targetPos, vector targetVelocity, int iterations, out float targetDistance, out float predictionTime, out vector muzzlePos, out vector muzzleDir)
static float CQB_COMPENSATION_MAX_MULTIPLIER
static float SURFACE_CORRECTION_MAX_ELEVATION_M
static float FIXED_AIM_POINT_TIMEOUT_LERP_FACTOR
void CorrectForSurface(out vector aimCorrectionVector, vector targetPos, vector aimPos, float speedMs, float targetDistance)
IEntity m_RelevantShooterEntity
float GetMuzzleAimData(BaseMuzzleComponent currentMuzzle, vector targetPos, vector targetVelocity, int iterations, out float targetDistance, out float predictionTime, out vector muzzlePos, out vector muzzleDir)
vector GetDynamicAimCorrectionVector(vector targetPos, vector aimVector, vector muzzlePos, vector targetVelocity, float targetDistance)
override TStringArray GetVariablesIn()
static string TARGET_ENTITY_PORT
static override bool VisibleInPalette()
vector m_vPointLeadAimPos
bool m_bRangeCompensation
void ValidateFixedAimPoint(out vector fixedAimPoint, vector targetPos, float time)
EWeaponType m_eCurrentWeaponType
static string AIMPOINT_PORT
override void OnInit(AIAgent owner)
void GetDynamicAimCorrectionFactors(out float angleFactor, out float distanceFactor)
void CreateFixedAimPoint(BaseWeaponComponent currentWeapon, BaseMuzzleComponent currentMuzzle, vector targetPos, vector targetVelocity, float initSpeedCoef, float time)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
SCR_AIUtilityComponent m_UtilityComponent
float m_fPointLeadAimTargetDist
static float GL_SURFACE_AIMING_MIN_DIST_M
static string VECTOR_OUT_PORT
static float CQB_COMPENSATION_MAX_DIST_M
static float FIXED_AIM_POINT_LEAD_TIME_FACTOR
static ref TStringArray s_aVarsOut
override TStringArray GetVariablesOut()
BaseWeaponManagerComponent m_WeaponManagerComponent
static float FIXED_AIM_POINT_MIN_SPEED_MS
static string TARGET_POSITION_PORT
static string VECTOR_IN_PORT
IEntity m_RelevantTargetEntity
EAIUnitType m_RelevantTargetEntityType
float m_fPointLeadAimPosTimeout
static float SOLUTION_UPDATE_INTERVAL_MS
bool m_bVelocityCompensation
static float FIXED_AIM_POINT_MIN_DIST_M
static ref TStringArray s_aVarsIn
ChimeraCharacter m_ShooterCharacter
static string INITIAL_SPEED_COEFFICIENT
IEntity GetRelevantEntity(IEntity entity)
CharacterControllerComponent m_CharacterControllerComponent
static override string GetOnHoverDescription()
Instance of created debug visualizer.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
array< string > TStringArray