void GetHitPoint()
        {
            if (vessel.packed)
            {
                return;
            }
            if (delayedEnabling)
            {
                return;
            }

            RaycastHit rayHit;
            Ray        ray = new Ray(cameraParentTransform.position + (50 * cameraParentTransform.forward), cameraParentTransform.forward);

            if (Physics.Raycast(ray, out rayHit, maxRayDistance - 50, 557057))
            {
                targetPointPosition = rayHit.point;

                if (!surfaceDetected && groundStabilized && !gimbalLimitReached)
                {
                    groundStabilized     = true;
                    groundTargetPosition = rayHit.point;

                    if (CoMLock)
                    {
                        Part p = rayHit.collider.GetComponentInParent <Part>();
                        if (p && p.vessel && p.vessel.Landed)
                        {
                            groundTargetPosition = p.vessel.CoM;
                        }
                    }
                    Vector3d newGTP = VectorUtils.WorldPositionToGeoCoords(groundTargetPosition, vessel.mainBody);
                    if (newGTP != Vector3d.zero)
                    {
                        bodyRelativeGTP = newGTP;
                    }
                }

                surfaceDetected = true;

                if (groundStabilized && !gimbalLimitReached && CMDropper.smokePool != null)
                {
                    if (CMSmoke.RaycastSmoke(ray))
                    {
                        surfaceDetected = false;
                    }
                }
            }
            else
            {
                targetPointPosition = cameraParentTransform.position + (maxRayDistance * cameraParentTransform.forward);
                surfaceDetected     = false;
            }
        }
Example #2
0
        protected void UpdateLaserTarget()
        {
            if (TargetAcquired)
            {
                if (lockedCamera && lockedCamera.groundStabilized && !lockedCamera.gimbalLimitReached && lockedCamera.surfaceDetected) //active laser target
                {
                    TargetPosition     = lockedCamera.groundTargetPosition;
                    TargetVelocity     = (TargetPosition - lastLaserPoint) / Time.fixedDeltaTime;
                    TargetAcceleration = Vector3.zero;
                    lastLaserPoint     = TargetPosition;

                    if (GuidanceMode == GuidanceModes.BeamRiding && TimeIndex > 0.25f && Vector3.Dot(GetForwardTransform(), part.transform.position - lockedCamera.transform.position) < 0)
                    {
                        TargetAcquired = false;
                        lockedCamera   = null;
                    }
                }
                else //lost active laser target, home on last known position
                {
                    if (CMSmoke.RaycastSmoke(new Ray(transform.position, lastLaserPoint - transform.position)))
                    {
                        //Debug.Log("Laser missileBase affected by smoke countermeasure");
                        float angle = VectorUtils.FullRangePerlinNoise(0.75f * Time.time, 10) * BDArmorySettings.SMOKE_DEFLECTION_FACTOR;
                        TargetPosition     = VectorUtils.RotatePointAround(lastLaserPoint, transform.position, VectorUtils.GetUpDirection(transform.position), angle);
                        TargetVelocity     = Vector3.zero;
                        TargetAcceleration = Vector3.zero;
                        lastLaserPoint     = TargetPosition;
                    }
                    else
                    {
                        TargetPosition = lastLaserPoint;
                    }
                }
            }
            else
            {
                ModuleTargetingCamera foundCam = null;
                bool parentOnly = (GuidanceMode == GuidanceModes.BeamRiding);
                foundCam = BDATargetManager.GetLaserTarget(this, parentOnly);
                if (foundCam != null && foundCam.cameraEnabled && foundCam.groundStabilized && BDATargetManager.CanSeePosition(foundCam.groundTargetPosition, vessel.transform.position, MissileReferenceTransform.position))
                {
                    Debug.Log("[BDArmory]: Laser guided missileBase actively found laser point. Enabling guidance.");
                    lockedCamera   = foundCam;
                    TargetAcquired = true;
                }
            }
        }