|
ProjectileHelper
1.02
Library of functions to assist with ballistic projectile calculations.
|
Class of static functions to help with ballistic projectile calculations. These functions assume that gravity acts in the y-axis. More...
Static Public Member Functions | |
| static float | ComputeSpeedToReachMaxFlatRange (float range, float gravity_negative, out float timeToLand) |
| Given a maximum range (on flat ground) and gravity, what is the maximum speed the projectile can be launched? Use case: The player can only throw grenades with a max range of 30 meters on flat ground. What is the max speed he can throw it? More... | |
| static bool | CanReachTargetWithSpeed (Vector3 startPosition, Vector3 targetPosition, float gravity_negative, float speed) |
| Given a start position, gravity and initial speed, can a projectile reach a target position? Use case: If my cannonballs always fire at 200m/sec, can it reach a target position? More... | |
| static bool | ComputeDirectionToHitTargetWithSpeed (Vector3 startPosition, Vector3 targetPosition, float gravity_negative, float speed, out Vector3 direction1, out Vector3 direction2) |
| Given a start position, gravity and initial speed, what direction should we fire the projectile to hit a target position? More... | |
| static bool | ComputeTimeToHitGround (Vector3 startPosition, Vector3 velocity, float groundLevel, float gravity_negative, out float timeToHit) |
| Given a start position, initial velocity (with direction) and gravity, how much time is needed to reach the ground (at a specified height level). Use case: Artillery has begun firing upon your position. How much time do you have to evacuate / take cover? More... | |
| static Vector3 | ComputePositionAtTimeAhead (Vector3 currentPosition, Vector3 velocity, float gravity_negative, float timeAhead) |
| Determine what position a projectile will be after a certain time, given its current position and velocity. Use case: To display the trajectory of a grenade before you throw it More... | |
| static Vector3 | ComputeVelocityAtTimeAhead (Vector3 currentPosition, Vector3 currentVelocity, float gravity_negative, float timeAhead) |
| Determine the velocity of a projectile after a certain time, given its current position and velocity. More... | |
| static Vector3 | ComputeVelocityToHitTargetAtTime (Vector3 startPosition, Vector3 targetPosition, float gravity_negative, float timeToTargetPosition) |
| Determine the velocity needed to hit a target position in exactly the given amount of time. Use case: you want to fire a catapult projectile to land at a specific position, giving the player exactly 4 seconds of warning time to escape More... | |
| static void | UpdateProjectile (ref Vector3 currentPosition, ref Vector3 currentVelocity, float gravity_negative, float deltaTime) |
| Update a projectile's current position and velocity, given the gravity and delta time More... | |
| static float | ComputeGravityToReachTargetWithSpeedAndElevation (float distanceOffset, float heightOffset, float elevationRadians, float speed) |
| Determine the gravity needed to reach a target distance and height with a given speed and elevation angle More... | |
| static bool | ComputeSpeedToReachTargetWithElevation (Vector3 startPosition, Vector3 targetPosition, float elevationRadians, float gravity_negative, ref float outSpeed) |
| Determine the speed needed to reach a target position given a starting elevation. More... | |
| static bool | ComputeSpeedToReachFlatRangeWithElevation (float elevationRadians, float range, float gravityNegative, out float speed) |
| Determine the speed needed to reach a certain range (on flat ground) given a starting elevation More... | |
| static bool | ComputeElevationToHitTargetWithSpeed (float heightOffset, float distanceOffset, float gravityNegative, float speed, bool useSmallerAngle, out float angleRadians) |
| Given an initial speed, what elevation angle is needed to hit a target at a specified height offset and flat distance away? More... | |
Class of static functions to help with ballistic projectile calculations. These functions assume that gravity acts in the y-axis.
|
static |
Given a start position, gravity and initial speed, can a projectile reach a target position? Use case: If my cannonballs always fire at 200m/sec, can it reach a target position?
| startPosition | Starting Position of the projectile. |
| targetPosition | Target Position of the projectile. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| speed | Initial speed of the projectile. |
|
static |
Given a start position, gravity and initial speed, what direction should we fire the projectile to hit a target position?
| startPosition | Starting Position of the projectile. |
| targetPosition | Target Position of the projectile. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| speed | Initial speed of the projectile. |
| direction1 | First possible direction for the projectile |
| direction2 | Second possible direction for the projectile |
|
static |
Given an initial speed, what elevation angle is needed to hit a target at a specified height offset and flat distance away?
| heightOffset | Difference in height of the target from the starting position |
| distanceOffset | Flat distance away from the starting position. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| speed | Initial speed of the projectile. |
| useSmallerAngle | Whether to calculate the smaller or larger elevation angle, since two elevations are possible. |
| angleRadians | Output: the elevation angle needed. |
|
static |
Determine the gravity needed to reach a target distance and height with a given speed and elevation angle
| distanceOffset | Flat distance away from the starting position. |
| heightOffset | Height difference from the starting position. |
| elevationRadians | Elevation angle the projectile will be fired at. |
| speed | The initial speed of the projectile. |
|
static |
Determine what position a projectile will be after a certain time, given its current position and velocity. Use case: To display the trajectory of a grenade before you throw it
| currentPosition | Current position of the projectile. |
| velocity | Current velocity of the projectile. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| timeAhead | The amount of time in the future at which you want to know the position |
|
static |
Determine the speed needed to reach a certain range (on flat ground) given a starting elevation
| elevationRadians | Elevation angle the projectile will be fired at. |
| range | Flat distance away from the starting position. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| speed | Output: Speed of projectile needed to reach the wanted range. |
|
static |
Given a maximum range (on flat ground) and gravity, what is the maximum speed the projectile can be launched? Use case: The player can only throw grenades with a max range of 30 meters on flat ground. What is the max speed he can throw it?
| range | Maximum range of the projectile on flat ground, in meters |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| timeToLand | Outputs the time taken for the projectile to reach max range on flat ground. In seconds. |
|
static |
Determine the speed needed to reach a target position given a starting elevation.
| startPosition | Starting position of the projectile. |
| targetPosition | Target position of the projectile. |
| elevationRadians | Elevation angle the projectile will be fired at. This should be less than PiBy2 radians, ie 90degrees. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| outSpeed | Output: The calculated speed needed. |
|
static |
Given a start position, initial velocity (with direction) and gravity, how much time is needed to reach the ground (at a specified height level). Use case: Artillery has begun firing upon your position. How much time do you have to evacuate / take cover?
| startPosition | Starting position of the projectile. |
| velocity | Initial velocity of the projectile. |
| groundLevel | The y-value of the ground level. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| timeToHit | Output: Time to reach the groundlevel specified. |
|
static |
Determine the velocity of a projectile after a certain time, given its current position and velocity.
| currentPosition | Current position of the projectile. |
| currentVelocity | Current velocity of the projectile. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| timeAhead | The amount of time in the future at which you want to know the velocity |
|
static |
Determine the velocity needed to hit a target position in exactly the given amount of time. Use case: you want to fire a catapult projectile to land at a specific position, giving the player exactly 4 seconds of warning time to escape
| startPosition | Starting position of the projectile. |
| targetPosition | Target position of the projectile. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| timeToTargetPosition | The amount of time the projectile should take to reach the target |
|
static |
Update a projectile's current position and velocity, given the gravity and delta time
| currentPosition | Current position of the projectile. Will be modified to give the new position. |
| currentVelocity | Current velocity of the projectile. Will be modified to give the new velocity. |
| gravity_negative | Acceleration due to gravity on y-axis. Should be negative, eg -9.8f |
| deltaTime | The amount of time elapsed since the last update |
1.8.13