Example #1
0
    public override void OnCollisionEnter(Receiver_Controller_FSM receiver, Collider2D col)
    {
        if (col.gameObject.tag == "Ball")
        {
            Transform ballGo = col.gameObject.transform.parent;

            //check the height of the ball
            //Debug.Log("Ball height: " + "<color=orange><b> " +  ballGo.transform.position.z  + "</b></color>");
            bool canCatchBall = ballGo.transform.position.z <= GameManager.Instance.catchableHeight;

            if (canCatchBall)
            {
                //catch ball
                col.gameObject.tag = "BallCaught";

                //ballGo.parent.GetComponent<Ball_Controller>().enabled = false;
                ballGo.parent             = receiver.transform;
                ballGo.transform.position = receiver.transform.position;

                Rigidbody ballRb = ballGo.GetComponent <Rigidbody>();
                ballRb.isKinematic = true;

                //set the game to be reset
                GameManager.Instance.ballCaught = true;
            }
        }
    }
Example #2
0
    public override void OnCollisionEnter(Receiver_Controller_FSM receiver, Collider2D col)
    {
        //catch ball
        if (col.gameObject.tag == "Ball")
        {
            col.gameObject.tag = "BallCaught";

            Transform ballGo = col.gameObject.transform.parent;
            //ballGo.parent.GetComponent<Ball_Controller>().enabled = false;
            ballGo.parent             = receiver.transform;
            ballGo.transform.position = receiver.transform.position;
        }
    }
    void OnSceneGUI()
    {
        EditorTarget_Route      routeTarget         = (EditorTarget_Route)target;
        Receiver_Controller_FSM receiver_controller = routeTarget.receiver_controller;

        if (receiver_controller.currentRoute != null)
        {
            int numOfRoutePoints = receiver_controller.currentRoute.routePoints.Length;

            //the lineSegments need a start and end point for EACH line, thus the *2
            Vector3[] lineSegments = new Vector3[numOfRoutePoints * 2];

            //Vector3 prevPoint = new Vector3(-2, -2, 0);
            Vector3 prevPoint = receiver_controller.startPos;

            int pointIndex = 0;
            for (int i = 0; i < numOfRoutePoints; i++)
            {
                //get the currentPoint
                Vector3 currPoint = receiver_controller.currentRoute.routePoints[i];
                currPoint = prevPoint + currPoint;

                //store the starting point of the line segment
                lineSegments[pointIndex] = prevPoint;
                pointIndex++;

                //store the endpoint of the line segment
                lineSegments[pointIndex] = currPoint;
                pointIndex++;

                prevPoint = currPoint;
            }

            /*
             * //Handles.DrawLine((Vector2)routeTarget.transform.position, (Vector2)routeTarget.receiver_controller.currentTarget);
             * Vector3[] lineSegments = new Vector3[4];
             * lineSegments[0] = new Vector3(-2, 2, 0);
             * //lineSegments[1] = lineSegments[0] + (Vector3)receiver_controller.currentRoute.routePoints[0];
             * //lineSegments[2] = lineSegments[1] + (Vector3)receiver_controller.currentRoute.routePoints[1];
             * lineSegments[1] = lineSegments[0] + new Vector3(1, 0, 0);
             * lineSegments[2] = lineSegments[1];
             * lineSegments[3] = lineSegments[2] + new Vector3(1, 1, 0);
             */

            Handles.DrawLines(lineSegments);
        }
    }
Example #4
0
    public override void EnterState(QB_Controller_FSM qb)
    {
        targetReceiver  = qb.Receiver_current.GetComponent <Receiver_Controller_FSM>();
        ball_Controller = qb.GetComponent <Ball_Controller>();

        //this is so that we throw imedialty when we enter the state
        if (targetIndicator == null)
        {
            targetIndicator = qb.InstantiateTargetIndicator(CalcTarget(qb));
        }
        else
        {
            targetIndicator.gameObject.SetActive(true);
            targetIndicator.position = CalcTarget(qb);
        }

        ball_Controller.target = targetIndicator;
        ball_Controller.Launch();
        GameManager.Instance.ballLaunched = true;
    }
Example #5
0
    public override void Update(Receiver_Controller_FSM receiver)
    {
        Vector2 localForward = receiver.transform.rotation * Vector2.right;

        receiver.myRb.AddForce(localForward * receiver.speed * Time.deltaTime);

        float angle = Vector2.SignedAngle(receiver.currentTarget - (Vector2)receiver.transform.position, new Vector2(1.0f, 0.0f));

        receiver.myRb.MoveRotation(Mathf.LerpAngle(receiver.myRb.rotation, -angle, receiver.rotationSpeed * Time.deltaTime));

        if (receiver.TargetReached())
        {
            Vector2 temp = receiver.currentRoute.GetNextRoutePoint();
            if (temp == Vector2.zero)
            {
                //this should happen if the last routePoint is reached
                receiver.TransitionToState(receiver.runFinished_State);
            }
            else
            {
                receiver.currentTarget = receiver.currentTarget + temp;
            }
        }
    }
Example #6
0
 public override void CleanUp(Receiver_Controller_FSM receiver)
 {
 }
Example #7
0
 public override void EnterState(Receiver_Controller_FSM receiver)
 {
 }
 public abstract void OnCollisionEnter(Receiver_Controller_FSM receiver, Collider2D col);
 public abstract void CleanUp(Receiver_Controller_FSM receiver);
 public abstract void Update(Receiver_Controller_FSM receiver);
 public abstract void EnterState(Receiver_Controller_FSM receiver);
Example #12
0
 public override void EnterState(QB_Controller_FSM qb)
 {
     targetReceiver  = qb.Receiver_current.GetComponent <Receiver_Controller_FSM>();
     ball_Controller = qb.GetComponent <Ball_Controller>();
 }
 public override void Update(Receiver_Controller_FSM receiver)
 {
 }
 public override void OnCollisionEnter(Receiver_Controller_FSM receiver, Collider2D col)
 {
 }