public static Vector3 GetPoint(this Collider2D col, ColliderPoint point)
        {
            switch (point)
            {
            case ColliderPoint.Centre:
                return(col.transform.position);

            case ColliderPoint.TopLeft:
                return(col.GetTopLeft());

            case ColliderPoint.TopRight:
                return(col.GetTopRight());

            case ColliderPoint.BottomLeft:
                return(col.GetBottomLeft());

            case ColliderPoint.BottomRight:
                return(col.GetBottomRight());

            case ColliderPoint.TopFace:
                return(col.GetTopFace());

            case ColliderPoint.LeftFace:
                return(col.GetLeftFace());

            case ColliderPoint.RightFace:
                return(col.GetRightFace());

            case ColliderPoint.BottomFace:
                return(col.GetBottomCenter());

            default:
                return(col.transform.position);
            }
        }
 // Use this for initialization
 void Start()
 {
     ani        = GetComponent <Animator>();
     voice      = GetComponent <AudioSource>();
     voice.clip = standup;
     voice.Play();
     Colli = point.GetComponent <ColliderPoint>();
 }
Beispiel #3
0
        public void MoveVertically()
        {
            ColliderPoint newPoint       = MovementState.CharacterPoint;
            bool          cornerRecovery = newPoint == ColliderPoint.Centre;

            if (cornerRecovery)
            {
                newPoint = MovementState.PreviousCharacterPoint;
            }

            switch (newPoint)
            {
            case ColliderPoint.TopLeft:
                newPoint = ColliderPoint.BottomLeft;
                break;

            case ColliderPoint.TopRight:
                newPoint = ColliderPoint.BottomRight;
                break;

            case ColliderPoint.BottomLeft:
                newPoint = ColliderPoint.TopLeft;
                break;

            case ColliderPoint.BottomRight:
                newPoint = ColliderPoint.TopRight;
                break;

            case ColliderPoint.TopFace:
                newPoint = ColliderPoint.BottomFace;
                break;

            case ColliderPoint.BottomFace:
                newPoint = ColliderPoint.TopFace;
                break;

            case ColliderPoint.LeftFace:
                newPoint = ColliderPoint.BottomLeft;
                break;

            case ColliderPoint.RightFace:
                newPoint = ColliderPoint.BottomRight;
                break;

            default:
                newPoint = ColliderPoint.BottomFace;
                break;;
            }
            if (cornerRecovery || (MovementState.PivotCollider.IsUpright() && (newPoint == ColliderPoint.TopLeft || newPoint == ColliderPoint.TopRight)))
            {
                MovementState.SetPivotCollider(MovementState.PivotCollider, MovementState.TargetPoint, newPoint);
            }
            else
            {
                MovementState.CharacterPoint = newPoint;
            }
            _climbHandler.CurrentClimbingState.PlayerPosition = newPoint;
        }
Beispiel #4
0
        private Vector3 GetPivotPositionWhenCorner(ColliderPoint targetPoint)
        {
            CornerCollider = PivotCollider.transform;

            Vector3 vAcross = targetPoint == ColliderPoint.TopRight ? CornerCollider.right : -CornerCollider.right;
            Vector3 vDown   = -CornerCollider.up;

            return(PivotCollider.GetPoint(targetPoint) + (vAcross.normalized * _colliderDimensions.x) + (vDown.normalized * _colliderDimensions.y));
        }
Beispiel #5
0
 public ClimbingState(Climb climb, Collider2D col, float movementSpeed, float animationSpeed, ColliderPoint pivot, ColliderPoint player, DirectionFacing climbSide)
 {
     Climb          = climb;
     PivotCollider  = col;
     MovementSpeed  = movementSpeed;
     AnimationSpeed = animationSpeed;
     PivotPosition  = pivot;
     PlayerPosition = player;
     ClimbSide      = climbSide;
     IsUpright      = col.IsUpright();
     IsCorner       = col.IsCorner();
     CanClimbDown   = col.CanClimbDown();
 }
Beispiel #6
0
 private static void OffEdge(DirectionFacing direction)
 {
     if (direction == DirectionFacing.Right)
     {
         _target = ColliderPoint.TopRight;
         _player = ColliderPoint.BottomLeft;
     }
     else
     {
         _target = ColliderPoint.TopLeft;
         _player = ColliderPoint.BottomRight;
     }
 }
Beispiel #7
0
 private static void Mantle(DirectionFacing direction)
 {
     if (direction == DirectionFacing.Right)
     {
         _target = ColliderPoint.TopRight;
         _player = ColliderPoint.LeftFace;
     }
     else
     {
         _target = ColliderPoint.TopLeft;
         _player = ColliderPoint.RightFace;
     }
 }
Beispiel #8
0
 private static void Hanging(DirectionFacing direction)
 {
     if (direction == DirectionFacing.Right)
     {
         _target = ColliderPoint.TopRight;
         _player = ColliderPoint.TopLeft;
     }
     else
     {
         _target = ColliderPoint.TopLeft;
         _player = ColliderPoint.TopRight;
     }
 }
Beispiel #9
0
        public void SetPivotCollider(Collider2D pivotCollider, ColliderPoint targetPoint, ColliderPoint characterPoint)
        {
            PivotCollider          = pivotCollider;
            Pivot.transform.parent = pivotCollider.transform.parent;

            if (pivotCollider.IsUpright() && (characterPoint == ColliderPoint.TopLeft || characterPoint == ColliderPoint.TopRight))
            {
                CharacterPoint           = ColliderPoint.Centre;
                PreviousCharacterPoint   = characterPoint;
                TargetPoint              = targetPoint;
                Pivot.transform.position = GetPivotPositionWhenCorner(targetPoint);
                UpdatePivot              = false;
            }
            else
            {
                CharacterPoint           = characterPoint;
                TargetPoint              = targetPoint;
                Pivot.transform.position = PivotCollider.GetPoint(TargetPoint);
                UpdatePivot              = true;
            }
        }
 // Use this for initialization
 void Start()
 {
     ani = GetComponent<Animator>();
     voice = GetComponent<AudioSource>();
     voice.clip = standup;
     voice.Play();
     Colli = point.GetComponent<ColliderPoint>();
 }
Beispiel #11
0
        public void BoxCastMove()
        {
            if (Time.timeSinceLevelLoad < 1)
            {
                return;
            }

            Bounds bounds = _motor.Collider.bounds;

            if (_downHit)
            {
                ColliderPoint hitLocation;

                float n = _downHit.normal.x;

                if (Mathf.Abs(n) < 0.02f)
                {
                    hitLocation = ColliderPoint.BottomFace;
                }
                else if (n > 0)
                {
                    hitLocation = ColliderPoint.BottomLeft;
                }
                else
                {
                    hitLocation = ColliderPoint.BottomRight;
                }

                _motor.MovementState.CharacterPoint = hitLocation;

                Vector3 offset = _motor.Collider.GetPoint(hitLocation);

                float x             = hitLocation == ColliderPoint.BottomFace ? bounds.center.x : _downHit.point.x;
                var   pivotPosition = new Vector3(x, _downHit.point.y);

                float rotation = _motor.Transform.rotation.eulerAngles.z;

                if (rotation != 0)
                {
                    if (rotation < 180)
                    {
                        _motor.Transform.RotateAround(pivotPosition, Vector3.forward, -rotation / 2);
                    }
                    else
                    {
                        _motor.Transform.RotateAround(pivotPosition, Vector3.forward, (360 - rotation) / 2);
                    }
                }

                _motor.MovementState.TrappedBetweenSlopes = _motor.MovementState.IsOnSlope &&
                                                            ((_leftHit && _downHit.normal.x < 0) ||
                                                             (_rightHit && _downHit.normal.x > 0));

                bool directionHit = _leftHit || _rightHit;
                if ((_reset && directionHit == false) || _motor.MovementState.Pivot.transform.parent == null || hitLocation != _previousColliderPoint || _downHit.collider != _motor.MovementState.PivotCollider || Vector2.Distance(_motor.MovementState.Pivot.transform.localPosition, _motor.MovementState.Pivot.transform.parent.InverseTransformPoint(pivotPosition)) > 0.05f)                //  _downHit.collider != _motor.MovementState.PivotCollider || leftHit || rightHit || hitLocation != _previousColliderPoint || Vector2.Distance(_motor.MovementState.Pivot.transform.position, bounds.center) > 10f)
                {
                    _motor.MovementState.SetPivotPoint(_downHit.collider, pivotPosition, _downHit.normal);
                }
                _previousColliderPoint = hitLocation;
                _reset = directionHit;

                if (_motor.MovementState.TrappedBetweenSlopes == false && directionHit == false)
                {
                    if (_lipHit)
                    {
                        _motor.MovementState.SetPivotPoint(_lipHit.collider, _lipHit.point, _lipHit.normal);
                        _motor.Transform.position = _motor.MovementState.Pivot.transform.position + _motor.Transform.position - offset;
                    }
                    else
                    {
                        _motor.MovementState.Normal = _downHit.normal;
                        _motor.MovementState.Pivot.transform.Translate(MoveAlongSurface(), Space.World);
                        _motor.Rigidbody.MovePosition(_motor.MovementState.Pivot.transform.position + _motor.Transform.position - offset);
                    }
                }
            }
            else
            {
                float rotation = _motor.Transform.rotation.eulerAngles.z;

                if (rotation != 0)
                {
                    if (rotation < 180)
                    {
                        _motor.Transform.Rotate(Vector3.forward, -rotation / 2);
                    }
                    else
                    {
                        _motor.Transform.Rotate(Vector3.forward, (360 - rotation) / 2);
                    }
                }

                _motor.MovementState.PivotCollider = null;
                _motor.Transform.Translate(_motor.MovementState.CurrentAcceleration, Space.World);
            }
        }