Example #1
0
        protected virtual void HandleGravity()
        {
            //If we have a Physicsbody, borrow their calculation since we dont want to do it twice...
            if (pb)
            {
                gravityUp      = pb.GravityUp;
                gravityRight   = pb.GravityRight;
                gravityForward = pb.GravityForward;
            }
            else
            {
                //Get the nearest gravitational field and use this as our primary sourse of data
                GameObject fieldTmp = GeoCoord.NearestGravitationalBody(transform.position);
                if (fieldTmp != nearestGravityField)
                {
                    nearestGravityField = fieldTmp;
                    gb = nearestGravityField.GetComponent <GravitationalBody>();
                }

                gravityUp = gb.GravityUp(transform);

                //Also collect right and forward while we are here
                gravityRight   = Vector3.Cross(rb.velocity.normalized, gravityUp);
                gravityForward = Vector3.Cross(gravityUp, gravityRight);

                //TODO: MOVE TO METHOD SO WE DONT HAVE DUPLICATE CODE
            }
        }
        protected virtual void CalculateUp()
        {
            //Get the nearest gravitational field and use this as our primary sourse of data
            GameObject fieldTmp = GeoCoord.NearestGravitationalBody(transform.position);
            if (fieldTmp != nearestGravityField && fieldTmp !=null) {
                nearestGravityField = fieldTmp;
                gb = nearestGravityField.GetComponent<GravitationalBody>();
            }

            if (gb) {
                gravityUp = gb.GravityUp(transform);

                //Also collect right and forward while we are here
                gravityRight = Vector3.Cross(rb.velocity.normalized, gravityUp);
                gravityForward = -Vector3.Cross(gravityUp, gravityRight);
            }
            

            //TODO: MOVE TO METHOD SO WE DONT HAVE DUPLICATE CODE

            //DEEEEBUG because this is probably wrong
            //Debug.DrawRay(transform.position, gravityUp * 10f, Color.green);
            //Debug.DrawRay(transform.position, gravityRight * 10f, Color.red);
            //Debug.DrawRay(transform.position, gravityForward * 10f, Color.blue);
        }