mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
updated projectile prediction
This commit is contained in:
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user