updated projectile prediction

This commit is contained in:
2024-05-26 08:01:05 +03:00
parent d435625757
commit c600d53b20
2 changed files with 19 additions and 4 deletions

View File

@@ -50,6 +50,9 @@ namespace uml::prediction
std::optional<float> ProjectileTravelTime(const Vector3& end, std::optional<float> ProjectileTravelTime(const Vector3& end,
const Projectile& projectile, const Projectile& projectile,
float angle) const; float angle) const;
[[nodiscard]]
bool IsTargetWasHit(const Vector3& end, const Projectile& projectile, float angle, float time) const;
}; };
}; };

View File

@@ -32,10 +32,7 @@ namespace uml::prediction
if (!projectilePitch.has_value()) [[unlikely]] if (!projectilePitch.has_value()) [[unlikely]]
return std::nullopt; return std::nullopt;
const auto timeToHit = ProjectileTravelTime(predictedTargetPosition, if (!IsTargetWasHit(predictedTargetPosition, projectile, projectilePitch.value(), time))
projectile,
projectilePitch.value());
if (!timeToHit.has_value() || timeToHit.value() > time)
continue; continue;
const auto delta2d = (predictedTargetPosition - projectile.m_origin).Length2D(); const auto delta2d = (predictedTargetPosition - projectile.m_origin).Length2D();
@@ -103,4 +100,19 @@ namespace uml::prediction
return std::nullopt; return std::nullopt;
} }
bool ProjectilePredictor::IsTargetWasHit(const Vector3 &end, const Projectile &projectile, const float angle,
const float time) const
{
auto launchAngles = projectile.m_origin.ViewAngleTo(end);
launchAngles.x = angle;
const auto velocity = Vector3::CreateVelocity(launchAngles, projectile.m_velocity);
auto currentPos = projectile.m_origin + velocity * time;
currentPos.z -= m_gravity * projectile.m_gravityMultiplier * std::pow(time, 2.f) * 0.5f;
return currentPos.DistTo(end) <= 10.f;
}
} }