예제 #1
0
        public void SlavedAim()
        {
            if (pausingAfterShot)
            {
                return;
            }

            turret.AimToTarget(slavedTargetPosition);
        }
예제 #2
0
        void SlavedAim()
        {
            float targetDistance = Vector3.Distance(weaponManager.slavedPosition, rockets[0].parent.transform.position);

            currentTgtRange = targetDistance;

            Vector3 targetPosition = weaponManager.slavedPosition;

            targetPosition += trajectoryOffset;
            targetPosition += weaponManager.slavedVelocity * predictedFlightTime;
            targetPosition += 0.5f * weaponManager.slavedAcceleration * predictedFlightTime * predictedFlightTime;
            //targetPosition -= vessel.srf_velocity * predictedFlightTime;


            turret.AimToTarget(targetPosition);
        }
예제 #3
0
        void UpdateModel()
        {
            //model rotation

            if (radarEnabled)
            {
                if (rotationTransform && canScan)
                {
                    Vector3 direction;
                    if (locked)
                    {
                        direction =
                            Quaternion.AngleAxis(canTrackWhileScan ? currentAngle : lockScanAngle, referenceTransform.up) *
                            referenceTransform.forward;
                    }
                    else
                    {
                        direction = Quaternion.AngleAxis(currentAngle, referenceTransform.up) * referenceTransform.forward;
                    }

                    Vector3 localDirection =
                        Vector3.ProjectOnPlane(rotationTransform.parent.InverseTransformDirection(direction), Vector3.up);
                    if (localDirection != Vector3.zero)
                    {
                        rotationTransform.localRotation = Quaternion.Lerp(rotationTransform.localRotation,
                                                                          Quaternion.LookRotation(localDirection, Vector3.up), 10 * TimeWarp.fixedDeltaTime);
                    }
                }

                //lock turret
                if (lockingTurret && canLock)
                {
                    if (locked)
                    {
                        lockingTurret.AimToTarget(lockedTarget.predictedPosition, lockingPitch, lockingYaw);
                    }
                    else
                    {
                        lockingTurret.ReturnTurret();
                    }
                }
            }
            else
            {
                if (rotationTransform)
                {
                    rotationTransform.localRotation = Quaternion.Lerp(rotationTransform.localRotation,
                                                                      Quaternion.identity, 5 * TimeWarp.fixedDeltaTime);
                }

                if (lockingTurret)
                {
                    lockingTurret.ReturnTurret();
                }
            }
        }
예제 #4
0
        void SlavedAim()
        {
            Vector3 targetPosition;
            Vector3 targetVel;
            Vector3 targetAccel;

            if (weaponManager.slavingTurrets)
            {
                targetPosition = weaponManager.slavedPosition;
                targetVel      = weaponManager.slavedVelocity;
                targetAccel    = weaponManager.slavedAcceleration;

                //targetPosition -= vessel.srf_velocity * predictedFlightTime;
            }
            else if (legacyGuardTarget)
            {
                targetPosition = legacyGuardTarget.CoM;
                targetVel      = legacyGuardTarget.srf_velocity;
                targetAccel    = legacyGuardTarget.acceleration;
            }
            else
            {
                targetInTurretView = false;
                return;
            }

            currentTgtRange = Vector3.Distance(targetPosition, rockets[0].parent.transform.position);


            targetPosition += trajectoryOffset;
            targetPosition += targetVel * predictedFlightTime;
            targetPosition += 0.5f * targetAccel * predictedFlightTime * predictedFlightTime;

            turret.AimToTarget(targetPosition);
            targetInTurretView = turret.TargetInRange(targetPosition, 2, maxTargetingRange);
        }
예제 #5
0
		//Aiming used if part has a turret module
		void Aim()
		{
			//AI control
			if(aiControlled && !slaved)
			{
				if(legacyTargetVessel)
				{
					targetPosition += legacyTargetVessel.rb_velocity * Time.fixedDeltaTime;
				}
				else if(!targetAcquired)
				{
					autoFire = false;
					return;
				}
			}



			if(!slaved && !aiControlled && (yawRange > 0 || maxPitch-minPitch > 0))
			{
				//MouseControl
				Vector3 mouseAim = new Vector3(Input.mousePosition.x/Screen.width, Input.mousePosition.y/Screen.height, 0);
				Ray ray = FlightCamera.fetch.mainCamera.ViewportPointToRay(mouseAim);
				RaycastHit hit;
				if(Physics.Raycast(ray, out hit, maxTargetingRange, 557057))
				{
					targetPosition = hit.point;

					//aim through self vessel if occluding mouseray
					Part p = hit.collider.gameObject.GetComponentInParent<Part>();
					if(p && p.vessel && p.vessel == vessel)
					{
						targetPosition = ray.direction * maxTargetingRange + FlightCamera.fetch.mainCamera.transform.position; 
					}
				}
				else
				{
					targetPosition = (ray.direction * (maxTargetingRange+(FlightCamera.fetch.Distance*0.75f))) + FlightCamera.fetch.mainCamera.transform.position;	
					if(legacyTargetVessel!=null && legacyTargetVessel.loaded)
					{
						targetPosition = ray.direction * Vector3.Distance(legacyTargetVessel.transform.position, FlightCamera.fetch.mainCamera.transform.position) + FlightCamera.fetch.mainCamera.transform.position;	
					}
				}
			}


			//aim assist
			Vector3 finalTarget = targetPosition;
			Vector3 originalTarget = targetPosition;
			targetDistance = Vector3.Distance(finalTarget, transform.position);
			targetLeadDistance = targetDistance;
			if((BDArmorySettings.AIM_ASSIST || aiControlled) && eWeaponType!=WeaponTypes.Laser)
			{
				float gAccel = (float) FlightGlobals.getGeeForceAtPosition(finalTarget).magnitude;
				float time = targetDistance/(bulletVelocity);

				if(targetAcquired)
				{
					float time2 = VectorUtils.CalculateLeadTime(finalTarget-fireTransforms[0].position, targetVelocity-vessel.srf_velocity, bulletVelocity);
					if(time2 > 0) time = time2;
					finalTarget += (targetVelocity-vessel.srf_velocity) * time; //target vessel relative velocity compensation

					Vector3 acceleration = targetAcceleration;
					finalTarget += (0.5f * acceleration * time * time); //target acceleration
				}
				else if(vessel.altitude < 6000)
				{
					float time2 = VectorUtils.CalculateLeadTime(finalTarget-fireTransforms[0].position, -part.rb.velocity, bulletVelocity);
					if(time2 > 0) time = time2;
					finalTarget += (-part.rb.velocity*(time+Time.fixedDeltaTime));  //this vessel velocity compensation against stationary
				}
				Vector3 up = (finalTarget - vessel.mainBody.transform.position).normalized;
				if(bulletDrop && vessel.srfSpeed < 750) finalTarget += (0.5f*gAccel*time*time*up);  //gravity compensation
				
				targetLeadDistance = Vector3.Distance(finalTarget, fireTransforms[0].position);

				fixedLeadOffset = originalTarget-finalTarget; //for aiming fixed guns to moving target	

				
				//airdetonation
				if(airDetonation)
				{
					if(targetAcquired)
					{
						detonationRange = Mathf.Clamp(targetLeadDistance, 500, maxAirDetonationRange) - 50f;
					}
					else
					{
						detonationRange = defaultDetonationRange;
					}
				}
				
			}

			if(airDetonation)
			{
				detonationRange *= UnityEngine.Random.Range(0.95f, 1.05f);
			}

			finalAimTarget = finalTarget;

			//final turret aiming
			if(slaved && !targetAcquired) return;
			if(turret)
			{
				bool origSmooth = turret.smoothRotation;
				if(aiControlled || slaved)
				{
					turret.smoothRotation = false;
				}
				turret.AimToTarget(finalTarget);
				turret.smoothRotation = origSmooth;
			}
		}