public override void Launch(Targetable enemy, GameObject attack, Transform firingPoint) { var homingMissile = attack.GetComponent <HomingLinearProjectile>(); if (homingMissile == null) { Debug.LogError("No HomingLinearProjectile attached to attack object"); return; } Vector3 startingPoint = firingPoint.position; Vector3 targetPoint = Ballistics.CalculateLinearLeadingTargetPoint( startingPoint, enemy.position, enemy.velocity, homingMissile.startSpeed, homingMissile.acceleration); homingMissile.SetHomingTarget(enemy); var attackAffector = GetComponent <AttackAffector>(); Vector3 direction = attackAffector.towerTargetter.turret.forward; Vector3 binormal = Vector3.Cross(direction, Vector3.up); Quaternion rotation = Quaternion.AngleAxis(fireVectorXRotationAdjustment, binormal); Vector3 adjustedFireVector = rotation * direction; homingMissile.FireInDirection(startingPoint, adjustedFireVector); PlayParticles(fireParticleSystem, startingPoint, targetPoint); }
/// <summary> /// Fires this projectile from a designated start point to a designated world coordinate. /// Automatically sets firing angle to suit launch speed unless angle is overridden, in which case launch speed is overridden to suit angle. /// </summary> /// <param name="startPoint">Start point of the flight.</param> /// <param name="targetPoint">Target point to fly to.</param> public virtual void FireAtPoint(Vector3 startPoint, Vector3 targetPoint) { transform.position = startPoint; Vector3 firingVector; switch (fireMode) { case BallisticFireMode.UseLaunchSpeed: firingVector = Ballistics.CalculateBallisticFireVectorFromVelocity(startPoint, targetPoint, startSpeed, arcPreference); firingAngle = Ballistics.CalculateBallisticFireAngle(startPoint, targetPoint, startSpeed, arcPreference); break; case BallisticFireMode.UseLaunchAngle: firingVector = Ballistics.CalculateBallisticFireVectorFromAngle(startPoint, targetPoint, firingAngle); startSpeed = firingVector.magnitude; break; default: throw new ArgumentOutOfRangeException(); } Fire(firingVector); }
public BallisticsCalculatorViewModel() { _FileName = ""; _TrajectoryPlot = new PlotModel(); _TrajectoryPlot.Title = "Trajectory"; _WindagePlot = new PlotModel(); _WindagePlot.Title = "Horizontal Deviation"; RaisePropertyChanged(nameof(TrajectoryPlot)); _BulletTypes = new List <string>(); string[] values = Enum.GetNames(typeof(BulletShapeEnum)); foreach (string B in values) { _BulletTypes.Add(B.ToString()); } EstimateBCCommand = new RelayCommand(GetTestBulletBC, null); OpenBCestimatorCommand = new RelayCommand(OpenBCestimator, null); RunPreShotCheckCommand = new RelayCommand(RunPreShotCheck, null); ShootCommand = new RelayCommand(Shoot, null); SaveFileCommand = new RelayCommand(SaveFile, null); SaveFileAsCommand = new RelayCommand(SaveFileAs, null); OpenRangeFinderCommand = new RelayCommand(OpenRangeFinder, null); ZeroLocationCommand = new RelayCommand(ZeroLocation, null); ShotLocationCommand = new RelayCommand(ShotLocation, null); DataPersistence lDP = new DataPersistence(); Ballistics lBCls; string lf = lDP.AppDataFolder + "\\default.bdf"; lBCls = lDP.ParseBallisticSolution(lf); _MyBallisticsCalculator = lBCls; if (_MyBallisticsCalculator.ShotDistance == 0) { _MyBallisticsCalculator.ShotDistance = _MyBallisticsCalculator.MaxRange() * 0.75; } Shoot(); }
public void BlockBallTrajectory() { gameManager.TipDrill(); //tdoo if (rb == null) { rb = GetComponent <Rigidbody>(); } //todo this code is used three times now REFACTOR transform.parent = null; rb.useGravity = true; BallisticMotion motion = GetComponent <BallisticMotion>(); Vector3 targetPos = transform.position + new Vector3(5, 5, 0); Vector3 diff = targetPos - transform.position; Vector3 diffGround = new Vector3(diff.x, 0f, diff.z); Vector3 fireVel, impactPos; Debug.Log("BeBlocked Ballistics"); //FTS Calculations https://github.com/forrestthewoods/lib_fts/tree/master/projects/unity/ballistic_trajectory float gravity; if (Ballistics.solve_ballistic_arc_lateral(transform.position, 1, targetPos, transform.position + new Vector3(10, 0, 0), 10, out fireVel, out gravity, out impactPos)) { transform.forward = diffGround; motion.Initialize(transform.position, gravity); motion.AddImpulse(fireVel); } //Debug.Log("Blocked at " + impactPos); }
/// <summary> /// Launches a single projectile at a single enemy from a single firing point /// </summary> /// <param name="enemy"> /// The enemy to target /// </param> /// <param name="projectile"> /// The projectile to attack /// </param> /// <param name="firingPoint"> /// The point to fire from /// </param> public override void Launch(Targetable enemy, GameObject projectile, Transform firingPoint) { Vector3 startPosition = firingPoint.position; var ballisticProjectile = projectile.GetComponent <BallisticProjectile>(); if (ballisticProjectile == null) { Debug.LogError("No ballistic projectile attached to projectile"); DestroyImmediate(projectile); return; } Vector3 targetPoint; if (ballisticProjectile.fireMode == BallisticFireMode.UseLaunchSpeed) { // use speed targetPoint = Ballistics.CalculateBallisticLeadingTargetPointWithSpeed( startPosition, enemy.position, enemy.velocity, ballisticProjectile.startSpeed, ballisticProjectile.arcPreference, Physics.gravity.y, 4); } else { // use angle targetPoint = Ballistics.CalculateBallisticLeadingTargetPointWithAngle( startPosition, enemy.position, enemy.velocity, ballisticProjectile.firingAngle, ballisticProjectile.arcPreference, Physics.gravity.y, 4); } ballisticProjectile.FireAtPoint(startPosition, targetPoint); ballisticProjectile.IgnoreCollision(LevelManager.instance.environmentColliders); PlayParticles(fireParticleSystem, startPosition, targetPoint); }
/// <summary> /// Fires this projectile from a designated start point to a designated world coordinate. /// </summary> /// <param name="startPoint">Start point of the flight.</param> /// <param name="targetPoint">Target point to fly to.</param> public virtual void FireAtPoint(Vector3 startPoint, Vector3 targetPoint) { startPoint.z = 1f; transform.position = startPoint; Fire(Ballistics.CalculateLinearFireVector2D(startPoint, targetPoint, _startSpeed)); }
void HandleShooting(RuntimeWeapon c) { //Vector3 origin = animatorHook.aimPivot.position; Vector3 origin = playerCamera.rayCamera.position; origin += playerCamera.rayCamera.forward * 0.5f; Vector3 targetPosition = inputVariables.aimPosition; Vector3 targetDirection = targetPosition - origin; bool isHit = false; Debug.DrawRay(origin, targetPosition); RaycastHit hit = Ballistics.RaycastShoot(origin, targetDirection, ref isHit, ignoreLayer); //RaycastHit hit; //if (Physics.Raycast(origin, targetDirection, out hit, 200, ignoreLayer)) /* * if (Physics.Raycast(origin, targetDirection, out hit, 100, ignoreLayer)) * { * isHit = true; * } */ if (isHit) { HandleBulletHit(hit, c); } }
public ApplyFlightNoisePartialInputDataEventArgs( Part Part, Ballistics Ballistics, FlowParameters FlowParameters) { this.Part = Part; this.Ballistics = Ballistics; this.FlowParameters = FlowParameters; }
protected void FireLeadingShot(Vector2 target, Vector2 velocity) { for (int i = 0; i < _shooterStats._projectilesPerShot; i++) { LinearProjectile projectile = GetObjectFromPool(); Vector3 targetLeadFireVector = Ballistics.CalculateLinearLeadingTargetPoint(transform.position, target, velocity, projectile._startSpeed, projectile._acceleration); projectile.FireAtPoint(_firepoint.position, targetLeadFireVector); } _currentTimeBetweenShotFired = 0f; }
public override Skill Clone(int value) { var tmp = new Ballistics { Description = Description, MaxValue = MaxValue, Name = Name, Value = value }; return tmp; }
public ActionResult Result(Ballistics ballistics) { // Call constructor and collect data from index page ballistics.SetBallistics(ballistics.Velocity, ballistics.Mass, ballistics.Diameter, ballistics.Distance, ballistics.TempFarenheit, ballistics.DragCoef, ballistics.WindDirection, ballistics.WindVelocityMPH); // contextDB.Ballistics.Add(ballistics); //OH GOD!!!!! ballistics.CalculatePressure(ballistics.TempCelcius); ballistics.DoBallisticsMath(); // ballistics math must run first ballistics.EstimateWind(); return(View("Result", ballistics)); }
/// <summary> /// Launches homing missile at a target from a starting position /// </summary> /// <param name="enemy"> /// The enemy to attack /// </param> /// <param name="attack"> /// The projectile used to attack /// </param> /// <param name="firingPoint"> /// The point the projectile is being fired from /// </param> public override void Launch(Targetable enemy, GameObject attack, Transform firingPoint) { var homingMissile = attack.GetComponent <HomingLinearProjectile>(); if (homingMissile == null) { Debug.LogError("No HomingLinearProjectile attached to attack object"); return; } Vector3 startingPoint = firingPoint.position; Vector3 targetPoint = Ballistics.CalculateLinearLeadingTargetPoint( startingPoint, enemy.position, enemy.velocity, homingMissile.startSpeed, homingMissile.acceleration); homingMissile.SetHomingTarget(enemy); homingMissile.FireAtPoint(startingPoint, targetPoint); PlayParticles(fireParticleSystem, startingPoint, targetPoint); }
/// <summary> /// Gets the ballistic path. /// </summary> /// <returns>The ballistic path.</returns> /// <param name="startPos">Start position.</param> /// <param name="forward">Forward direction.</param> /// <param name="velocity">Velocity.</param> /// <param name="timeResolution">Time from frame to frame.</param> /// <param name="maxTime">Max time to simulate, will be clamped to reach height 0 (aprox.).</param> public static Vector3[] GetBallisticPath(Vector3 startPos, Vector3 forward, float velocity, float timeResolution, float maxTime = Mathf.Infinity) { maxTime = Mathf.Min(maxTime, Ballistics.GetTimeOfFlight(velocity, Vector3.Angle(forward, Vector3.up) * Mathf.Deg2Rad, startPos.y)); Vector3[] positions = new Vector3[Mathf.CeilToInt(maxTime / timeResolution)]; Vector3 velVector = forward * velocity; int index = 0; Vector3 curPosition = startPos; for (float t = 0.0f; t < maxTime; t += timeResolution) { if (index >= positions.Length) { break;//rounding error using certain values for maxTime and timeResolution } positions[index] = curPosition; curPosition += velVector * timeResolution; velVector += Physics.gravity * timeResolution; index++; } return(positions); }
public void PassFootBallToMovingTarget(QB ballThrower, OffPlayer receiver, FootBall footBall, float arcType, float power) { isComplete = true; SetGameManager(); gameManager.AttemptPass(ballThrower, receiver, this, arcType, power); //todo, this is ugly. Probably should be a bool for isComplete if (rb == null) { rb = GetComponent <Rigidbody>(); } //targetPos = GetPositionIn(2, wr); transform.parent = null; rb.useGravity = true; BallisticMotion motion = GetComponent <BallisticMotion>(); Vector3 targetPos = receiver.transform.position; Vector3 diff = targetPos - transform.position; Vector3 diffGround = new Vector3(diff.x, 0f, diff.z); Vector3 fireVel, impactPos; Vector3 velocity = receiver.navMeshAgent.velocity; //FTS Calculations https://github.com/forrestthewoods/lib_fts/tree/master/projects/unity/ballistic_trajectory float gravity; if (Ballistics.solve_ballistic_arc_lateral(transform.position, power, targetPos + Vector3.up, velocity, arcType, out fireVel, out gravity, out impactPos)) { GameObject go = Instantiate(targetMarker, impactPos, Quaternion.LookRotation(ballThrower.transform.position + new Vector3(0, 1, 0))); go.name = "footballMarker"; go.transform.parent = FindObjectOfType <FootBall>().transform; Destroy(go, 2); transform.forward = diffGround; motion.Initialize(transform.position, gravity); motion.AddImpulse(fireVel); gameManager.ThrowTheBall(ballThrower, receiver, this, impactPos, arcType, power, isComplete); //todo the football stores whether the pass is complete or not, not sure if thats a good idea. } //Debug.Log("Firing at " + impactPos); }
protected Vector3 GetHeading() { if (m_HomingTarget == null) { return(Vector3.zero); } Vector3 heading; if (leadTarget) { heading = Ballistics.CalculateLinearLeadingTargetPoint(transform.position, m_HomingTarget.position, m_TargetVelocity, m_Rigidbody.velocity.magnitude, acceleration, leadingPrecision) - transform.position; } else { heading = m_HomingTarget.position - transform.position; } return(heading.normalized); }
private void SetSniperLineTarget(PointerEventData pointer) { Vector3 aimingDirection = GetAimingDirection(pointer); var trajectory = Ballistics.Trajectory( AimOriginWorldCoordinates, aimingDirection.normalized * Cannon.MissileSpeed, Physics2D.gravity // does not account for settings on missile ); float trajectoryLength = Math.Min( MaxTrajectoryLength, aimingDirection.magnitude); trajectoryLength = aimingDirection.magnitude; var linePoints = new LinkedList <Vector3>(); Vector3 previousPoint = line.positionCount > 0 ? line.GetPosition(0) : Vector3.zero; float totalLineLength = 0f; float simulationTime = 0; while (totalLineLength < trajectoryLength) { Vector3 currentPoint = trajectory(simulationTime); totalLineLength += (currentPoint - previousPoint).magnitude; simulationTime += Time.fixedDeltaTime; //simulationTime += TrajectoryEstimationTimeStep; previousPoint = currentPoint; linePoints.AddLast(currentPoint); } line.positionCount = linePoints.Count; line.SetPositions(linePoints.ToArray()); }
public ActionResult Index() { Ballistics ballistics = new Ballistics(); return(View("Index", ballistics)); }
// Solve quartic function: c0*x^4 + c1*x^3 + c2*x^2 + c3*x + c4. // Returns number of solutions. public static int SolveQuartic(double c0, double c1, double c2, double c3, double c4, out double s0, out double s1, out double s2, out double s3) { s0 = double.NaN; s1 = double.NaN; s2 = double.NaN; s3 = double.NaN; double[] coeffs = new double[4]; double z, u, v, sub; double A, B, C, D; double sq_A, p, q, r; int num; /* normal form: x^4 + Ax^3 + Bx^2 + Cx + D = 0 */ A = c1 / c0; B = c2 / c0; C = c3 / c0; D = c4 / c0; /* substitute x = y - A/4 to eliminate cubic term: x^4 + px^2 + qx + r = 0 */ sq_A = A * A; p = -3.0 / 8 * sq_A + B; q = 1.0 / 8 * sq_A * A - 1.0 / 2 * A * B + C; r = -3.0 / 256 * sq_A * sq_A + 1.0 / 16 * sq_A * B - 1.0 / 4 * A * C + D; if (IsZero(r)) { /* no absolute term: y(y^3 + py + q) = 0 */ coeffs[3] = q; coeffs[2] = p; coeffs[1] = 0; coeffs[0] = 1; num = Ballistics.SolveCubic(coeffs[0], coeffs[1], coeffs[2], coeffs[3], out s0, out s1, out s2); } else { /* solve the resolvent cubic ... */ coeffs[3] = 1.0 / 2 * r * p - 1.0 / 8 * q * q; coeffs[2] = -r; coeffs[1] = -1.0 / 2 * p; coeffs[0] = 1; SolveCubic(coeffs[0], coeffs[1], coeffs[2], coeffs[3], out s0, out s1, out s2); /* ... and take the one real solution ... */ z = s0; /* ... to build two quadric equations */ u = z * z - r; v = 2 * z - p; if (IsZero(u)) { u = 0; } else if (u > 0) { u = System.Math.Sqrt(u); } else { return(0); } if (IsZero(v)) { v = 0; } else if (v > 0) { v = System.Math.Sqrt(v); } else { return(0); } coeffs[2] = z - u; coeffs[1] = q < 0 ? -v : v; coeffs[0] = 1; num = Ballistics.SolveQuadric(coeffs[0], coeffs[1], coeffs[2], out s0, out s1); coeffs[2] = z + u; coeffs[1] = q < 0 ? v : -v; coeffs[0] = 1; if (num == 0) { num += Ballistics.SolveQuadric(coeffs[0], coeffs[1], coeffs[2], out s0, out s1); } if (num == 1) { num += Ballistics.SolveQuadric(coeffs[0], coeffs[1], coeffs[2], out s1, out s2); } if (num == 2) { num += Ballistics.SolveQuadric(coeffs[0], coeffs[1], coeffs[2], out s2, out s3); } } /* resubstitute */ sub = 1.0 / 4 * A; if (num > 0) { s0 -= sub; } if (num > 1) { s1 -= sub; } if (num > 2) { s2 -= sub; } if (num > 3) { s3 -= sub; } return(num); }
public PreciseJewel2() { Name = "Precise Jewel 2"; Skill = new Ballistics(1); Type = SlotType.Medium; }
// Solve the firing arc with a fixed lateral speed. Vertical speed and gravity varies. // This enables a visually pleasing arc. // // proj_pos (Vector3): point projectile will fire from // lateral_speed (float): scalar speed of projectile along XZ plane // target_pos (Vector3): point projectile is trying to hit // max_height (float): height above Max(proj_pos, impact_pos) for projectile to peak at // // fire_velocity (out Vector3): firing velocity // gravity (out float): gravity necessary to projectile to hit precisely max_height // impact_point (out Vector3): point where moving targetPlayer will be hit // // return (bool): true if a valid solution was found public static bool solve_ballistic_arc_lateral(Vector3 proj_pos, float lateral_speed, Vector3 target, Vector3 target_velocity, float max_height_offset, out Vector3 fire_velocity, out float gravity, out Vector3 impact_point) { // Handling these cases is up to your project's coding standards Debug.Assert(proj_pos != target && lateral_speed > 0, "Ballistics.solve_ballistic_arc_lateral called with invalid data"); // Initialize output variables fire_velocity = Vector3.zero; gravity = 0f; impact_point = Vector3.zero; // Ground plane terms Vector3 targetVelXZ = new Vector3(target_velocity.x, 0f, target_velocity.z); Vector3 diffXZ = target - proj_pos; diffXZ.y = 0; // Derivation // (1) Base formula: |P + V*t| = S*t // (2) Substitute variables: |diffXZ + targetVelXZ*t| = S*t // (3) Square both sides: Dot(diffXZ,diffXZ) + 2*Dot(diffXZ, targetVelXZ)*t + Dot(targetVelXZ, targetVelXZ)*t^2 = S^2 * t^2 // (4) Quadratic: (Dot(targetVelXZ,targetVelXZ) - S^2)t^2 + (2*Dot(diffXZ, targetVelXZ))*t + Dot(diffXZ, diffXZ) = 0 float c0 = Vector3.Dot(targetVelXZ, targetVelXZ) - lateral_speed * lateral_speed; float c1 = 2f * Vector3.Dot(diffXZ, targetVelXZ); float c2 = Vector3.Dot(diffXZ, diffXZ); double t0, t1; int n = Ballistics.SolveQuadric(c0, c1, c2, out t0, out t1); // pick smallest, positive time bool valid0 = n > 0 && t0 > 0; bool valid1 = n > 1 && t1 > 0; float t; if (!valid0 && !valid1) { return(false); } else if (valid0 && valid1) { t = Mathf.Min((float)t0, (float)t1); } else { t = valid0 ? (float)t0 : (float)t1; } // Calculate impact point impact_point = target + (target_velocity * t); // Calculate fire velocity along XZ plane Vector3 dir = impact_point - proj_pos; fire_velocity = new Vector3(dir.x, 0f, dir.z).normalized *lateral_speed; // Solve system of equations. Hit max_height at t=.5*time. Hit targetPlayer at t=time. // // peak = y0 + vertical_speed*halfTime + .5*gravity*halfTime^2 // end = y0 + vertical_speed*time + .5*gravity*time^s // Wolfram Alpha: solve b = a + .5*v*t + .5*g*(.5*t)^2, c = a + vt + .5*g*t^2 for g, v float a = proj_pos.y; // initial float b = Mathf.Max(proj_pos.y, impact_point.y) + max_height_offset; // peak float c = impact_point.y; // final gravity = -4 * (a - 2 * b + c) / (t * t); fire_velocity.y = -(3 * a - 4 * b + c) / t; return(true); }
public ActionResult _Results(Ballistics ballistics) { return(PartialView("_Results", ballistics)); }
public FlightSoundLevel GetFlightSoundLevel(Ballistics ballistics, FlowParameters flowParameters, FrequencyBand frequencyBand) { return(flightNoiseModel.GetFlightSoundLevel(ballistics, flowParameters, frequencyBand)); }
public ActionResult _EnterData(Ballistics ballistics) { return(PartialView("_EnterData", ballistics)); }
public ActionResult Index(Ballistics ballistics) { return(View("Index", ballistics)); }