// Start moving the projectile over the trajectory using UsedBallisticsSettings, // the current GameObject's position, the rotationTransform's orientation, and // the velocity vector. public void Start() { BallisticsSettings ballistics = UsedBallisticsSettings; _time = 0.0f; _isActive = true; _trajectory3D = new Trajectory3D(Projectile3D, transform.position, velocity); _headingFrequency = Mathf.Sqrt(_trajectory3D.k) * ballistics.rotationStiffness; _headingDamping = ballistics.rotationDamping; _windVelocity = ballistics.windVelocity; if (rotationTransform == null) { rotationTransform = transform; } AdvanceTime(0.0f); }
void FixedUpdate() { remainingReloadTime = Mathf.Max(remainingReloadTime - Time.deltaTime, 0.0f); UpdateTrackedPositionsAndVelocities(); // get the latest plan for the latest data bool planIsReadyForLaunch; Vector3 absoluteProjectileVelocity = TurretHelper.UpdatePlan( _planners, _projectileKinematics, launchTransform.position, _velocity, _targetPosition, _targetVelocity, remainingReloadTime, ref _plannedFlightTime, out planIsReadyForLaunch); // output debug widgets if requested if (drawDebugTrajectoryPlan) { Trajectory3D trajectory3D = new Trajectory3D( _projectileKinematics.Projectile3D, launchTransform.position + _velocity * remainingReloadTime, absoluteProjectileVelocity); TurretHelper.DebugDrawLastTrajectory(trajectory3D, _plannedFlightTime); } // if a plan has been found, update the turret's aim bool hasPlan = absoluteProjectileVelocity.sqrMagnitude > 0; Vector3 relativeProjectileVelocity = absoluteProjectileVelocity - _velocity; if (hasPlan) { UpdateTurretAim(relativeProjectileVelocity); // if the plan and aim is good enough, and there's no more remaining // weapon reload time, then launch. bool stillImprovingAimAccuracy = UpdateTurretOrientation(); if (canLaunch && planIsReadyForLaunch && !stillImprovingAimAccuracy && Vector3.Dot(relativeProjectileVelocity, launchTransform.forward) > 0) { Launch(relativeProjectileVelocity); } } }