Example #1
0
        private void DrawRollingFrictionGizmo(Vector2 locationIn2DSpace, Color gizmoColor)
        {
            Vector2 correctedRollingFrictionForce = Vector2Utils.GetRotatedVelocityVector(GetRollingFriction(), transform.rotation.eulerAngles.z) * GIZMO_SCALE;

            Gizmos.color = gizmoColor;
            Gizmos.DrawLine(locationIn2DSpace, locationIn2DSpace + correctedRollingFrictionForce);
        }
Example #2
0
        private void DrawBrakingFrictionGizmo(Vector2 locationIn2DSpace, Color noGripGizmoColor, Color maxGripGizmoColor)
        {
            float minFrictionCoefficient     = _tyreData.MinFrictionCoefficient() * (IsTyreRolling ? _tyreData.ForwardsFrictionCoefficient : _tyreData.SidewaysFrictionCoefficient);
            float maxFrictionCoefficient     = _tyreData.MaxFrictionCoefficient() * (IsTyreRolling ? _tyreData.ForwardsFrictionCoefficient : _tyreData.SidewaysFrictionCoefficient);
            float currentRelativeCoefficient = ((IsTyreRolling ? _forwardsGripCoefficient : _lockedBrakesGripCoefficient) - minFrictionCoefficient) / (maxFrictionCoefficient - minFrictionCoefficient);

            Gizmos.color = Color.Lerp(noGripGizmoColor, maxGripGizmoColor, currentRelativeCoefficient);

            Vector2 correctedBrakingFrictionForce = Vector2Utils.GetRotatedVelocityVector(GetBrakingFriction(), transform.rotation.eulerAngles.z) * GIZMO_SCALE;

            Gizmos.DrawLine(locationIn2DSpace, locationIn2DSpace + correctedBrakingFrictionForce);
        }
Example #3
0
        public void PlaceOnGrid(Transform gridPlacement)
        {
            if (gridPlacement == null)
            {
                return;
            }

            _frontAxle.DisableTyres();
            _rearAxle.DisableTyres();

            _rigidbody.velocity        = Vector2.zero;
            _rigidbody.angularVelocity = 0f;

            float   offsetDistance = (_body.BodyLength / 2f) + 1f;
            float   rotation       = gridPlacement.rotation.eulerAngles.z;
            Vector2 offset         = Vector2Utils.GetRotatedVelocityVector(new Vector2(0f, -offsetDistance), rotation);

            transform.rotation = Quaternion.Euler(0f, 0f, rotation);
            transform.position = new Vector2(gridPlacement.position.x, gridPlacement.position.y) + offset;

            _frontAxle.EnableTyres();
            _rearAxle.EnableTyres();
        }