Exemple #1
0
    void Update()
    {
        if (targeter.target != null)
        {
            targetVelocity = Vector2.zero;

            moveToRange = true;
            tryToAttack = true;
            //todo allow for optional wait times so that more complex if conditions dont happen every frame
            switch (targeter.CurrentRange)
            {
            case Target.LONG_RANGE:
                LongRangeDecision(targeter.target);
                break;

            case Target.MID_RANGE:
                MidRangeDecision(targeter.target);
                break;

            case Target.CLOSE_RANGE:
                CloseRangeDecision(targeter.target);
                break;
            }
            if ((Time.time - lastThought) > thinkPeriod)
            {
                lastThought = Time.time;
                UpdateAvoidVec();
            }
            if (hasEntityController)
            {
                if ((flagHandler.CommonFlags & CommonFlags.MoveWithInput) != CommonFlags.None)
                {
                    if (moveToRange)
                    {
                        targetVelocity = targeter.TargetDirection();
                        float speed = SpeedDecision();
                        targetVelocity.x *= entityController.Facing * speed;
                        tryToAttack       = false;
                    }
                    if (hasAvoider && AvoidVector != Vector3.zero)
                    {
                        if (!(Mathf.Sign(targetVelocity.x) == Mathf.Sign(AvoidVector.x) &&
                              Mathf.Abs(targetVelocity.x) > Mathf.Abs(AvoidVector.x)))
                        {
                            targetVelocity.x = AvoidVector.x;
                            tryToAttack      = false;
                        }
                    }

                    /*
                     * if (hasAvoider && avoider.AvoidVector != Vector3.zero)
                     * {
                     *      if (!(Mathf.Sign(targetVelocity.x) == Mathf.Sign(avoider.AvoidVector.x) &&
                     *              Mathf.Abs(targetVelocity.x) > Mathf.Abs(avoider.AvoidVector.x)))
                     *      {
                     *              targetVelocity.x = avoider.AvoidVector.x;
                     *              tryToAttack = false;
                     *      }
                     * }*/
                }
                entityController.TargetVelocity = targetVelocity;
            }

            if (tryToAttack)
            {
                moveHandler.CheckMoves(linksToAttempt);
            }
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (Time.timeScale == 0)
        {
            return;
        }
        FlagData flagData      = flagHandler.Flags;
        Vector2  movementInput = Vector2.zero;

        movementInput.x = directionalInput.x;
        movementInput.y = directionalInput.y;
        //movementInput.x = Input.GetAxisRaw("Horizontal");
        //movementInput.y = Input.GetAxisRaw("Vertical");
        Vector2 previousTarget = entityController.TargetVelocity;
        Vector2 targetVelocity = Vector2.zero;

        foreach (InputBuffer b in inputBuffers)
        {
            b.Update();
        }
        if ((flagData.commonFlags & CommonFlags.CanTurn) != CommonFlags.None)
        {
            if (movementInput.x != 0)
            {
                Vector3 sca = transform.localScale;
                if (movementInput.x > 0)
                {
                    sca.x = 1;
                    entityController.Facing = 1;
                }
                else
                {
                    sca.x = -1;
                    entityController.Facing = -1;
                }
                transform.localScale = sca;
            }
        }
        if ((flagData.commonFlags & CommonFlags.MoveWithInput) != CommonFlags.None)
        {
            targetVelocity.x = movementInput.x;
            if ((flagData.commonFlags & CommonFlags.YMovement) != CommonFlags.None)
            {
                targetVelocity.y = movementInput.y * movementSpeed;
            }
            float xSpeedMult = movementSpeed;
            if (!entityController.Grounded)
            {
                xSpeedMult = airMovementSpeed;
            }
            targetVelocity.x *= xSpeedMult;
        }
        if ((flagData.commonFlags & CommonFlags.MovementCancel) != CommonFlags.None)
        {
            if (movementInput.x != 0)
            {
                moveHandler.EnterGenericState("", 0.3f);
            }
        }
        if ((flagData.commonFlags & CommonFlags.Dodgeing) != CommonFlags.None)
        {
            if (targetVelocity == Vector2.zero)
            {
                if (previousTarget == Vector2.zero)
                {
                    targetVelocity.x = entityController.Facing * movementSpeed;
                    targetVelocity  *= 6f;
                }
                else
                {
                    targetVelocity = previousTarget;
                }
            }
            else
            {
                //targetVelocity.y /= 2f;

                targetVelocity *= 6f;
            }


            if (moveHandler.OverDodge != 0)
            {
                targetVelocity.y = movementSpeed;
            }

            /*animatorVec = targetVelocity;
             * animatorVec.x *= facing;
             * return animatorVec;*/
        }

        entityController.TargetVelocity = targetVelocity;
        moveHandler.CheckMoves(CurrentMoves);
    }