Ejemplo n.º 1
0
        public void Land()
        {
            Ray        checkAction = new Ray(this.cTransform.position, -this.cTransform.up);
            RaycastHit hitInfo     = new RaycastHit();

            Physics.Raycast(checkAction, out hitInfo, 4f);

            if (hitInfo.collider != null)
            {
                if (hitInfo.collider.gameObject != null)
                {
                    Gravity target = hitInfo.collider.gameObject.GetComponent <Gravity> ();
                    if (target == null)
                    {
                        if (hitInfo.collider.gameObject.transform.parent != null)
                        {
                            target = hitInfo.collider.gameObject.transform.parent.GetComponent <Gravity> ();
                            if (target == null)
                            {
                                if (hitInfo.collider.gameObject.transform.parent.parent != null)
                                {
                                    target = hitInfo.collider.gameObject.transform.parent.parent.GetComponent <Gravity> ();
                                }
                            }
                        }
                    }
                    if (target != null)
                    {
                        this.currentGrav       = target;
                        this.cTransform.parent = this.currentGrav.transform;
                        this.state             = LightShipState.Landing;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void TakeOff()
 {
     this.parkingSpot            = null;
     this.state                  = LightShipState.Flying;
     this.cRigidbody.isKinematic = false;
     if (this.motherShip != null)
     {
         this.cRigidbody.velocity = this.motherShip.GetVelocity();
     }
     this.cTransform.parent = null;
     this.motherShip        = null;
     this.currentGrav       = null;
 }
Ejemplo n.º 3
0
		public void LeaveControl () {
			if (this.spaceShip != null) {
				this.spaceShip.engineOn = false;
				this.spaceShip.pitchOn = 0;
				this.spaceShip.rollOn = 0;
			}

			if (this.lightShip != null) {
				this.lightShip.engineOn = false;
				this.lightShip.pitchOn = 0;
				this.lightShip.rollOn = 0;
				this.transform.parent = this.lightShip.transform.parent;
				this.cRigidbody.isKinematic = false;
				this.GetComponent<Collider>().enabled = true;
				this.state = HumanoidState.Stand;
				this.currentGrav = this.transform.parent.GetComponent<Gravity> ();
			}

			this.cRigidbody.isKinematic = false;
			this.GetComponent<Collider>().enabled = true;

			this.seat = null;
			this.spaceShip = null;
			this.lightShip = null;
			this.head.localRotation = Quaternion.identity;
			this.state = HumanoidState.Stand;
		}
Ejemplo n.º 4
0
		public void FixedUpdate () {
			
			if (this.state == LightShipState.Flying) {
				if (this.engineOn) {
					this.cRigidbody.AddForce (this.cTransform.forward * this.enginePower / 2f);
				}
				else {
					this.cRigidbody.AddForce (this.cTransform.forward * this.enginePower / 8f);
				}

				if (this.powerOn) {
					this.engineOn = true;
					this.cRigidbody.AddForce (this.cTransform.forward * this.enginePower);
				}
				
				if (this.rollOn != 0) {
					this.cRigidbody.AddTorque (this.rollOn * this.cTransform.forward * this.rollPower);
				}
				
				if (this.pitchOn != 0) {
					this.cRigidbody.AddTorque (this.pitchOn * this.cTransform.right * this.pitchPower);
				}

				this.speed = this.cRigidbody.velocity.magnitude;
			}
			
			if (this.state == LightShipState.Parked) {
				if (this.powerOn) {
					this.TakeOff ();
				}
			}
			
			if (this.state == LightShipState.Parking) {
				if (this.powerOn) {
					this.cTransform.parent = null;
					this.state = LightShipState.Flying;
				}

				if (this.parkingSpot != null) {
					this.cRigidbody.AddForce ((this.parkingSpot.transform.position - this.cTransform.position).normalized);
					this.cRigidbody.MoveRotation (Quaternion.Lerp (this.cTransform.rotation, this.parkingSpot.transform.rotation, Time.fixedDeltaTime));

					if ((this.cTransform.position - this.parkingSpot.transform.position).sqrMagnitude < 0.1f) {
						if (Vector3.Angle (this.cTransform.up, this.parkingSpot.transform.up) < 1f) {
							this.DockOnShip ();
						}
					}
				}
			}
			
			if (this.state == LightShipState.Landed) {
				if (this.powerOn) {
					this.TakeOff ();
				}
			}
			
			if (this.state == LightShipState.Landing) {
				if (this.powerOn) {
					this.cTransform.parent = null;
					this.currentGrav = null;
					this.state = LightShipState.Flying;
				}

				if (this.rollOn != 0) {
					this.cRigidbody.AddTorque (this.rollOn * this.cTransform.forward * this.rollPower);
				}
				
				if (this.pitchOn != 0) {
					this.cRigidbody.AddTorque (this.pitchOn * this.cTransform.right * this.pitchPower);
				}
				
				if (this.currentGrav != null) {
					if (this.currentGrav.GType == Gravity.GravityType.Cartesian) {
						this.cRigidbody.AddForce (- this.cTransform.parent.up * this.currentGrav.gravity / 5f);
					}
					else if (this.currentGrav.GType == Gravity.GravityType.Spherical) {
						this.cRigidbody.AddForce (- (this.cTransform.position - this.cTransform.parent.position).normalized * this.currentGrav.gravity / 5f);
					}
				}

				if (this.cRigidbody.velocity.sqrMagnitude < 0.05f) {
					this.DockOnGround ();
				}
			}
		}
Ejemplo n.º 5
0
		public void Land () {
			Ray checkAction = new Ray (this.cTransform.position, - this.cTransform.up);
			RaycastHit hitInfo = new RaycastHit ();
			Physics.Raycast (checkAction, out hitInfo, 4f);
			
			if (hitInfo.collider != null) {
				if (hitInfo.collider.gameObject != null) {
					Gravity target = hitInfo.collider.gameObject.GetComponent<Gravity> ();
					if (target == null) {
						if (hitInfo.collider.gameObject.transform.parent != null) {
							target = hitInfo.collider.gameObject.transform.parent.GetComponent<Gravity> ();
							if (target == null) {
								if (hitInfo.collider.gameObject.transform.parent.parent != null) {
									target = hitInfo.collider.gameObject.transform.parent.parent.GetComponent<Gravity> ();
								}
							}
						}
					}
					if (target != null) {
						this.currentGrav = target;
						this.cTransform.parent = this.currentGrav.transform;
						this.state = LightShipState.Landing;
					}
				}
			}
		}
Ejemplo n.º 6
0
		public void TakeOff () {
			this.parkingSpot = null;
			this.state = LightShipState.Flying;
			this.cRigidbody.isKinematic = false;
			if (this.motherShip != null) {
				this.cRigidbody.velocity = this.motherShip.GetVelocity ();
			}
			this.cTransform.parent = null;
			this.motherShip = null;
			this.currentGrav = null;
		}
Ejemplo n.º 7
0
        public void FixedUpdate()
        {
            if (this.state == LightShipState.Flying)
            {
                if (this.engineOn)
                {
                    this.cRigidbody.AddForce(this.cTransform.forward * this.enginePower / 2f);
                }
                else
                {
                    this.cRigidbody.AddForce(this.cTransform.forward * this.enginePower / 8f);
                }

                if (this.powerOn)
                {
                    this.engineOn = true;
                    this.cRigidbody.AddForce(this.cTransform.forward * this.enginePower);
                }

                if (this.rollOn != 0)
                {
                    this.cRigidbody.AddTorque(this.rollOn * this.cTransform.forward * this.rollPower);
                }

                if (this.pitchOn != 0)
                {
                    this.cRigidbody.AddTorque(this.pitchOn * this.cTransform.right * this.pitchPower);
                }

                this.speed = this.cRigidbody.velocity.magnitude;
            }

            if (this.state == LightShipState.Parked)
            {
                if (this.powerOn)
                {
                    this.TakeOff();
                }
            }

            if (this.state == LightShipState.Parking)
            {
                if (this.powerOn)
                {
                    this.cTransform.parent = null;
                    this.state             = LightShipState.Flying;
                }

                if (this.parkingSpot != null)
                {
                    this.cRigidbody.AddForce((this.parkingSpot.transform.position - this.cTransform.position).normalized);
                    this.cRigidbody.MoveRotation(Quaternion.Lerp(this.cTransform.rotation, this.parkingSpot.transform.rotation, Time.fixedDeltaTime));

                    if ((this.cTransform.position - this.parkingSpot.transform.position).sqrMagnitude < 0.1f)
                    {
                        if (Vector3.Angle(this.cTransform.up, this.parkingSpot.transform.up) < 1f)
                        {
                            this.DockOnShip();
                        }
                    }
                }
            }

            if (this.state == LightShipState.Landed)
            {
                if (this.powerOn)
                {
                    this.TakeOff();
                }
            }

            if (this.state == LightShipState.Landing)
            {
                if (this.powerOn)
                {
                    this.cTransform.parent = null;
                    this.currentGrav       = null;
                    this.state             = LightShipState.Flying;
                }

                if (this.rollOn != 0)
                {
                    this.cRigidbody.AddTorque(this.rollOn * this.cTransform.forward * this.rollPower);
                }

                if (this.pitchOn != 0)
                {
                    this.cRigidbody.AddTorque(this.pitchOn * this.cTransform.right * this.pitchPower);
                }

                if (this.currentGrav != null)
                {
                    if (this.currentGrav.GType == Gravity.GravityType.Cartesian)
                    {
                        this.cRigidbody.AddForce(-this.cTransform.parent.up * this.currentGrav.gravity / 5f);
                    }
                    else if (this.currentGrav.GType == Gravity.GravityType.Spherical)
                    {
                        this.cRigidbody.AddForce(-(this.cTransform.position - this.cTransform.parent.position).normalized * this.currentGrav.gravity / 5f);
                    }
                }

                if (this.cRigidbody.velocity.sqrMagnitude < 0.05f)
                {
                    this.DockOnGround();
                }
            }
        }