Example #1
0
        // Update is called once per frame
        void Update()
        {
            // Turn toward the lead target position
            if (targetLeader.Target != null)
            {
                // Set the target leader's intercept speed as the current missile speed
                targetLeader.InterceptSpeed = engines.GetCurrentMaxSpeedByAxis(false).z;

                Vector3 toTargetVector        = targetLeader.Target.transform.position - transform.position;
                Vector3 adjustedLeadTargetPos = transform.position + (targetLeader.LeadTargetPosition - transform.position).normalized * toTargetVector.magnitude;

                float   leadTargetAngle = Vector3.Angle(toTargetVector, adjustedLeadTargetPos - transform.position);
                float   amount          = Mathf.Clamp(maxLeadTargetAngle / leadTargetAngle, 0, 1);
                Vector3 nextTargetPos   = amount * adjustedLeadTargetPos + (1 - amount) * targetLeader.Target.transform.position;

                Maneuvring.TurnToward(transform, nextTargetPos, maxRotationAngles, steeringPIDController);
                engines.SetRotationThrottleValues(steeringPIDController.GetControlValues());
            }
            else
            {
                engines.SetRotationThrottleValues(Vector3.zero);
            }
        }
        // Update is called once per frame
        void Update()
        {
            if (engines != null && rBody != null)
            {
                if (speedBarRenderer != null)
                {
                    speedBarRenderer.material.SetFloat("_FillAmount", rBody.velocity.magnitude / engines.GetCurrentMaxSpeedByAxis(false).z);
                }

                if (speedText != null)
                {
                    speedText.text = ((int)rBody.velocity.magnitude).ToString();
                }
            }
        }