Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float UMathUtils::CalculateTrajectory(float distance, float gravity, float projectileVelocity)
- {
- return 0.5f * FMath::Asin((-gravity * distance) / (projectileVelocity*projectileVelocity));
- }
- float UMathUtils::FirstOrderInterceptTime(float speed, FVector targetRelativePosition, FVector targetRelativeVelocity)
- {
- float velocitySquared = targetRelativeVelocity.SizeSquared();
- if (velocitySquared < 0.001f)
- velocitySquared = 0.0f;
- float a = velocitySquared - speed * speed;
- if (FMath::Abs(a) < 0.001f)
- {
- float t = -targetRelativePosition.SizeSquared() / (2.0f * FVector::DotProduct(targetRelativeVelocity, targetRelativePosition));
- return FMath::Max(t, 0.0f);
- }
- float b = 2.0f * FVector::DotProduct(targetRelativeVelocity, targetRelativePosition);
- float c = targetRelativeVelocity.SizeSquared();
- float determinant = b * b - 4.0f * a * c;
- if (determinant > 0.0f)
- {
- float t1 = (-b + FMath::Sqrt(determinant)) / (2.0f * a);
- float t2 = (-b - FMath::Sqrt(determinant)) / (2.0f * a);
- if (t1 > 0)
- {
- if (t2 > 0) return FMath::Min(t1, t2);
- return t1;
- }
- return FMath::Max(t2, 0.0f);
- }
- if (determinant < 0) return 0;
- return FMath::Max(-b / (2.0f * a), 0.0f);
- }
- FVector UMathUtils::FirstOrderIntercept(FVector location, FVector velocity, float speed, FVector targetLocation, FVector targetVelocity)
- {
- FVector targetRelativePosition = targetLocation - location;
- FVector targetRelativeVelocity = targetVelocity - velocity;
- float t = FirstOrderInterceptTime(speed, targetRelativePosition, targetRelativeVelocity);
- return targetLocation + t * targetRelativeVelocity;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement