Example #1
0
        private void satellite_fixed_update()
        {
            float   bearing = (internal_transform.localEulerAngles.z + 90) * Mathf.Deg2Rad;
            Vector2 input   = new Vector2(Mathf.Cos(bearing), Mathf.Sin(bearing)) * DebrisNoirsInput.get_accelerate();

            // add velocity based on input
            planetaria_rigidbody.relative_velocity += input * Time.fixedDeltaTime;
            Vector2 velocity = planetaria_rigidbody.relative_velocity;

            // drag in coincident direction varies from coefficient of 1->~0.8->~0.5
            float   similarity          = Vector2.Dot(velocity.normalized, input);
            float   drag_modifier       = Mathf.Lerp(0.6f, 1.0f, (similarity + 1f) / 2);
            Vector2 coincident_velocity = input != Vector2.zero ? (Vector2)Vector3.Project(velocity, input) : velocity;

            coincident_velocity *= Mathf.Pow(drag_modifier, Time.deltaTime);

            // get perpendicular velocity (unmodified)
            Vector2 perpendicular_velocity = input != Vector2.zero ? Vector3.ProjectOnPlane(velocity, input) : Vector3.zero;

            // apply velocity changes
            planetaria_rigidbody.relative_velocity = coincident_velocity + perpendicular_velocity;

            // apply unusued drag
            //planetaria_rigidbody.relative_velocity *= Mathf.Pow(0.8f, Time.deltaTime * (1f - input_direction.magnitude));
        }
Example #2
0
        public Vector2 acceleration_direction()
        {
            float   current_angle = internal_transform.localEulerAngles.z;
            Vector2 direction     = new Vector2(Mathf.Cos(current_angle * Mathf.Deg2Rad), Mathf.Sin(current_angle * Mathf.Deg2Rad));

            if (DebrisNoirsInput.get_accelerate() == 1)
            {
                fuel += Time.deltaTime;
            }
            else
            {
                fuel -= Time.deltaTime;
            }
            fuel = Mathf.Clamp01(fuel);
            return(direction * fuel);
        }