Exemple #1
0
    public override void Act(Transform fish)
    {
        Debug.Log("JUMP");
        GameObject GO        = GameObject.FindWithTag("Fishy");
        GameObject downwater = GameObject.FindWithTag("WaterDown");
        //GameObject upwater = GameObject.FindWithTag("WaterUp");
        Vector3    currentAngles  = GO.GetComponent <Rigidbody>().transform.rotation.eulerAngles;
        Quaternion targetRotation = Quaternion.Euler(-55.0f, currentAngles.y, 0.0f);

        GO.GetComponent <Rigidbody>().transform.rotation = Quaternion.Lerp(GO.GetComponent <Rigidbody>().transform.rotation, targetRotation, 33.0f * Time.fixedDeltaTime);

        // need to add an event listener so that the rotation completes before the force is added.
        // In the meantime, multiplied fixedDeltaTime by 33 so that the rotation is finished. It rotates too fast though, almost instant.

        Vector3 moveDirection = new Vector3(GO.GetComponent <Rigidbody>().transform.forward.x, GO.GetComponent <Rigidbody>().transform.forward.y, GO.GetComponent <Rigidbody>().transform.forward.z);

        //FishScript.nonKinematicTime = 3.4f;
        //if (GO.rigidbody.isKinematic == true) {
        downwater.GetComponent <Collider>().enabled = false;
        //upwater.collider.enabled = false;
        GO.GetComponent <Rigidbody>().isKinematic = false;
        GO.GetComponent <FSMFishController>().setRagdollState(true);
        if (GO.GetComponent <Animation>())
        {
            GO.GetComponent <Animation>().Stop();
        }
        FSMFishController fishController = fish.GetComponent <FSMFishController>();

        jumpForce = fishController.jumpForce;
        GO.GetComponent <Rigidbody>().AddForce(moveDirection * jumpForce);
        //FishScript.health -= 1.0f; //jumping takes energy so health takes a hit
    }
    void OnTap(TapGesture gesture)
    {
        Debug.Log("onTap");
        if (gesture.Selection == GO)          // && (FishScript.dead != true) ) { // requires tapping on the fish object to make it jump
        // Set the transition in the State Machine
        {
            FSMFishController fishController = GO.GetComponent <FSMFishController>();
            //fishController.jumpForce = 2500.0f;
            fishController.fishWasTapped = true;

            /* MOVE THE CODE TO TURN OFF KINEMATIC AND ADDFORCE TO JumpState.cs IN STATE MACHINE
             * // To make it easy and fun to play, set the angle of the fish pointing automatically upwards for a good jumping angle (currently -40°)
             * Vector3 currentAngles = GO.rigidbody.transform.rotation.eulerAngles;
             * Quaternion targetRotation = Quaternion.Euler(0.0f, currentAngles.y, 55.0f);
             * GO.rigidbody.transform.rotation = Quaternion.Lerp(GO.rigidbody.transform.rotation, targetRotation, 33.0f * Time.fixedDeltaTime);
             * // need to add an event listener so that the rotation completes before the force is added.
             * // In the meantime, multiplied fixedDeltaTime by 33 so that the rotation is finished. It rotates too fast though, almost instant.
             * Vector3 moveDirection =  new Vector3(GO.rigidbody.transform.right.x, GO.rigidbody.transform.right.y, GO.rigidbody.transform.right.z);
             * FishScript.nonKinematicTime = 3.4f;
             * TurnOffKinematic(GO);
             * GO.rigidbody.AddForce (moveDirection * jumpForce);
             * FishScript.health -= 1.0f; //jumping takes energy so health takes a hit
             */// END MOVE THE CODE TO STATE MACHINE
        }
    }
Exemple #3
0
    public override void Act(Transform fish)
    {
        float turnAmount = 5.0f;

        Debug.Log("BUMP");
        GameObject GO = GameObject.FindWithTag("Fishy");         // why search for GO, can just use Transform fish?

        FSMFishController fishController = fish.GetComponent <FSMFishController>();

        // if a bump has recently happened, turn the fish to the opposite direction. Should this be a separate state?
        if ((Time.time - fishController.timeAtPreviousBump) < fishController.timeBetweenBumps)
        {
            // rotate 180 degrees more or less
            turnAmount = 171.0f;
        }
        Vector3 bumpDirection = new Vector3(GO.GetComponent <Rigidbody>().transform.forward.x, GO.GetComponent <Rigidbody>().transform.forward.y + turnAmount, GO.GetComponent <Rigidbody>().transform.forward.z);

        bumpDirection.Normalize();
        // rotate the fish around when it bumps so it moves away from obstacle
        //Vector3 moveDirection =  new Vector3(GO.rigidbody.transform.forward.x, GO.rigidbody.transform.forward.y + turnAmount, GO.rigidbody.transform.forward.z);
        //moveDirection.Normalize();
        //Quaternion targetRotation = Quaternion.LookRotation(moveDirection);
        //fish.transform.rotation = Quaternion.Slerp(fish.transform.rotation, targetRotation, 10.0f * Time.fixedDeltaTime);
        fish.transform.Rotate(Vector3.up, turnAmount);

        GO.GetComponent <Rigidbody>().isKinematic = false;
        if (GO.GetComponent <Animation>())
        {
            GO.GetComponent <Animation>().Stop();
        }
        fishController.setRagdollState(true);
        GO.GetComponent <Rigidbody>().AddForce(bumpDirection * bumpForce);
        //FishScript.health -= 1.0f; //jumping takes energy so health takes a hit
    }
    public override void Act(Transform fish)
    {
        Debug.Log("On the TURNING AWAY");
        FSMFishController fishController = fish.GetComponent <FSMFishController>();

        fishController.turning(fishController.newDirection);
    }
Exemple #5
0
    public override void Reason(Transform fish)
    {
        Debug.Log("HIT THE WATER");
        GameObject        theFish        = GameObject.FindWithTag("Fishy");
        FSMFishController fishController = theFish.GetComponent <FSMFishController>();

        fishController.SetTransition(Transition.UnderWater);
    }
Exemple #6
0
 public override void Reason(Transform fish)
 {
     if (fish.transform.position.y < 14.4f)
     {
         GameObject        theFish        = GameObject.FindWithTag("Fishy");
         FSMFishController fishController = theFish.GetComponent <FSMFishController>();
         fishController.SetTransition(Transition.AtSurface);
     }
 }
Exemple #7
0
    public override void Act(Transform fish)
    {    /*
          *     fish.rigidbody.isKinematic = false;
          *     Debug.Log(fish.rigidbody.isKinematic);
          */
        Debug.Log("I taut i taw a obstacle");
        FSMFishController fishController = fish.GetComponent <FSMFishController>();

        fishController.findClearDirection();
    }
Exemple #8
0
    public override void Reason(Transform fish)
    {
        Debug.Log("I taut I taw...");
        FSMFishController fishController = fish.GetComponent <FSMFishController>();

        if (fishController.foundClearDirection)
        {
            fishController.foundClearDirection = false;
            fishController.SetTransition(Transition.FoundClearDirection);
        }
    }
Exemple #9
0
    public override void Reason(Transform fish)
    {
        //if (Input.GetKey(KeyCode.J))
        //{
        GameObject        theFish        = GameObject.FindWithTag("Fishy");
        FSMFishController fishController = theFish.GetComponent <FSMFishController>();

        fishController.fishWasTapped = false;
        fish.GetComponent <FSMFishController>().SetTransition(Transition.HasJumped);
        //}
    }
Exemple #10
0
    public override void Reason(Transform fish)
    {
        // Can I not use the Transform fish instead of searching for GameObject?
        // Keep a count of # of times bumped within an amount of time, so if it's stuck in bumping over and over, it does
        // something to get out of that, like turning around and facing the other way, or perhaps some random direction
        GameObject        theFish        = GameObject.FindWithTag("Fishy");
        FSMFishController fishController = theFish.GetComponent <FSMFishController>();

        fishController.fishWasTapped = false;
        fish.GetComponent <FSMFishController>().SetTransition(Transition.HasBumped);
    }
Exemple #11
0
    public override void Reason(Transform fish)
    {
        Debug.Log("JUMPING ABOVE WATER");
        GameObject        theFish        = GameObject.FindWithTag("Fishy");
        FSMFishController fishController = theFish.GetComponent <FSMFishController>();

        if (fish.transform.position.y <= lastY)         // fish has reached the apex of jump, so transition to falling state
        {
            fishController.SetTransition(Transition.ReachedApex);
        }
        lastY = fish.transform.position.y;
    }
    public override void Reason(Transform fish)
    {
        Debug.Log("On the TURNING AWAY");
        FSMFishController fishController = fish.GetComponent <FSMFishController>();

        if (fishController.turnIsComplete)
        {
            fishController.turnIsComplete = false;
            fishController.updateMoveSpeed();
            fishController.SetTransition(Transition.TurnIsComplete);
        }
    }
    public override void Reason(Transform fish)
    {
        Debug.Log("JUMPING but Underwater");
        GameObject        theFish        = GameObject.FindWithTag("Fishy");
        FSMFishController fishController = theFish.GetComponent <FSMFishController>();

        if (theFish.transform.position.y > 14.0f)         // substutute waterlevel variable later
        {
            Debug.Log("About to go ABOVE water");
            fish.GetComponent <FSMFishController>().SetTransition(Transition.AboveWater);
        }
    }
Exemple #14
0
    //public override void Reason(Transform player, Transform npc)
    public override void Reason(Transform fish)
    {
        //Check the distance with player tank
        //When the distance is near, transition to chase state
        //if (Vector3.Distance(npc.position, player.position) <= 300.0f)
        //{
        //Debug.Log("Switch to Swim State");
        //GameObject theFish = GameObject.FindWithTag("Fishy");
        FSMFishController fishController = fish.GetComponent <FSMFishController>();

        //tappedFish = fishController.fishWasTapped;
        //bumpedFish = fishController.bumped;
        if (fishController.fishWasTapped)         // || theFish.transform.position.y > 14.7f) // jumps either if tapped, or if fish is "driven" above water
        {
            fishController.jumpForce = 1100.0f;
            // fish.GetComponent<FSMFishController>().SetTransition(Transition.Tapped);
            fishController.SetTransition(Transition.Tapped);
        }
        else if (fish.transform.position.y > 14.8f)         // fish has been "driven" above water
        {
            fishController.jumpForce = 0.0f;
            fishController.SetTransition(Transition.Tapped);
        }
        else if (fishController.bumped)
        {
            fishController.SetTransition(Transition.BumpedIntoSomething);
            Debug.Log(fishController.bumped + ": BUMPED while Swimming!!!!");
            fishController.bumped = false;
            Debug.Log("Bumped is now: " + fishController.bumped);
        }
        else if (fishController.foundClearDirection)
        {
            fishController.foundClearDirection = false;
            fishController.SetTransition(Transition.SwimmingToTurning);
        }

        if (fish.transform.position.y < 0.0f)
        {
            fishController.SetTransition(Transition.GoneBelow);
        }
        // fishController.OnTriggerStay();
        //}
    }