Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        directionInputX = Input.GetAxisRaw("Horizontal");
        directionInputY = Input.GetAxisRaw("Vertical");

        //The idea behind this is left/right, up/down firing options. Jump
        //key will probably need to be reassigned in project settings for this
        //to play well.
        action1 = Input.GetButtonDown("Fire1");
        action2 = Input.GetButtonDown("Fire2");
        action3 = Input.GetButtonDown("Fire3");
        action4 = Input.GetButtonDown("Jump");


        if (action1)
        {
            myOverheadController.Attack("up");
        }
        if (action2)
        {
            myOverheadController.Attack("right");
        }
        if (action3)
        {
            myOverheadController.Attack("down");
        }
        if (action4)
        {
            myOverheadController.Attack("left");
        }

        myOverheadController.setActiveXVel(directionInputX);
        myOverheadController.setActiveYVel(directionInputY);
    }
Beispiel #2
0
    public override void UpdateState()
    {
        //if somehow we're here with no target, go back to the last state
        if (charManager.targetTransform == null)
        {
            this.machine.RevertState();
        }

        //if the target has gotten too far, untarget and move back to idle
        float dis = Vector3.Distance(charController.transform.position, charManager.targetTransform.position);

        if (dis > maximumDistance)
        {
            Debug.Log("Lost target");
            charManager.targetTransform = null;
            machine.ChangeState("idle");
        }

        //figure out which direction to walk to go towards target X
        float dirx = 0f;
        float distanceThreshold = charController.speed / 8;
        float relativeX         = charController.transform.position.x - charManager.targetTransform.position.x;

        if (relativeX < distanceThreshold * -1)
        {
            dirx = 1f;
        }
        if (relativeX > distanceThreshold)
        {
            dirx = -1f;
        }

        charController.setActiveXVel(dirx);


        //figure out which direction to walk to go towards target Y
        float diry      = 0f;
        float relativeY = charController.transform.position.y - charManager.targetTransform.position.y;

        if (relativeY < distanceThreshold * -1)
        {
            diry = 1f;
        }
        if (relativeY > distanceThreshold)
        {
            diry = -1f;
        }

        charController.setActiveYVel(diry);
    }