Example #1
0
    public void DoFixedUpdate()
    {
        if (isHit > 0)
        {
            isHit -= Time.fixedDeltaTime;
            return;
        }

        // Check if both controllers are ready
        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        if (p1InputController == null || !p1InputController.isReady || p2InputController == null || !p2InputController.isReady)
        {
            return;
        }

        if (UFE.freeCamera)
        {
            return;
        }

        transform.position += (movement * Time.fixedDeltaTime);

        hurtBox.position = gameObject.transform.position;
        if (projectileRenderer != null && (hurtBox.followXBounds || hurtBox.followYBounds))
        {
            hurtBox.rendererBounds = GetBounds();
            hitBox.rendererBounds  = GetBounds();
        }

        blockableArea.position = transform.position;
        if (!opControlsScript.isBlocking &&
            !opControlsScript.blockStunned &&
            opControlsScript.currentSubState != SubStates.Stunned &&
            opHitBoxesScript.TestCollision(blockableArea) != Vector3.zero)
        {
            opControlsScript.CheckBlocking(true);
        }

        if (data.projectileCollision)
        {
            if (opControlsScript.projectiles.Count > 0)
            {
                foreach (ProjectileMoveScript projectile in opControlsScript.projectiles)
                {
                    if (projectile == null)
                    {
                        continue;
                    }
                    if (projectile.hitBox == null)
                    {
                        continue;
                    }
                    if (projectile.hurtBox == null)
                    {
                        continue;
                    }

                    if (HitBoxesScript.TestCollision(new HitBox[] { projectile.hitBox }, new HurtBox[] { hurtBox }, HitConfirmType.Hit, mirror) != Vector3.zero)
                    {
                        if (data.impactPrefab != null)
                        {
                            GameObject hitEffect = (GameObject)Instantiate(data.impactPrefab, transform.position, Quaternion.Euler(0, 0, data.directionAngle));
                            UFE.DelaySynchronizedAction(delegate(){ try{ Destroy(hitEffect); }catch {} }, data.impactDuration);
                        }
                        totalHits--;
                        if (totalHits <= 0)
                        {
                            destroyMe = true;
                        }
                        isHit = spaceBetweenHits;
                        transform.Translate(movement * -1 * Time.fixedDeltaTime);
                        break;
                    }
                }
            }
        }

        if (opHitBoxesScript.TestCollision(new HurtBox[] { hurtBox }, HitConfirmType.Hit) != Vector3.zero &&
            opControlsScript.ValidateHit(hit))
        {
            if (data.impactPrefab != null)
            {
                GameObject hitEffect = (GameObject)Instantiate(data.impactPrefab, transform.position, Quaternion.Euler(0, 0, data.directionAngle));
                UFE.DelaySynchronizedAction(delegate(){ try{ Destroy(hitEffect); }catch {} }, data.impactDuration);
            }
            totalHits--;
            if (totalHits <= 0)
            {
                UFE.DelaySynchronizedAction(delegate(){ try{ Destroy(gameObject); }catch {} }, (float)(2 / UFE.config.fps));
            }


            if (opControlsScript.currentSubState != SubStates.Stunned && opControlsScript.isBlocking && opControlsScript.TestBlockStances(hit.hitType))
            {
                myControlsScript.AddGauge(data.gaugeGainOnBlock);
                opControlsScript.AddGauge(data.opGaugeGainOnBlock);
                opControlsScript.GetHitBlocking(hit, 20, transform.position);

                if (data.moveLinkOnBlock != null)
                {
                    myControlsScript.CastMove(data.moveLinkOnBlock, true, data.forceGrounded);
                }
            }
            else if (opControlsScript.potentialParry > 0 && opControlsScript.TestParryStances(hit.hitType))
            {
                opControlsScript.AddGauge(data.opGaugeGainOnParry);
                opControlsScript.GetHitParry(hit, 20, transform.position);

                if (data.moveLinkOnParry != null)
                {
                    myControlsScript.CastMove(data.moveLinkOnParry, true, data.forceGrounded);
                }
            }
            else
            {
                myControlsScript.AddGauge(data.gaugeGainOnHit);
                opControlsScript.AddGauge(data.opGaugeGainOnHit);
                opControlsScript.GetHit(hit, 30, Vector3.zero);

                if (data.moveLinkOnStrike != null)
                {
                    myControlsScript.CastMove(data.moveLinkOnStrike, true, data.forceGrounded);
                }
            }

            isHit = opControlsScript.GetHitFreezingTime(data.hitStrength) * 1.2f;
            opControlsScript.CheckBlocking(false);
        }
    }
    void FixedUpdate()
    {
        //if (myPhysicsScript.freeze) return;
        if (isHit > 0)
        {
            isHit -= Time.deltaTime;
            return;
        }
        transform.Translate(movement * Time.deltaTime);

        if (opHitBoxesScript.testCollision(blockableArea) != Vector3.zero)
        {
            opControlsScript.CheckBlocking(true);
        }

        if (data.projectileCollision)
        {
            RaycastHit raycastHit = new RaycastHit();
            if (Physics.SphereCast(transform.position, data.hitRadius * (data.speed * .1f), Vector3.forward, out raycastHit, 1, opProjectileMask))
            {
                if (data.impactPrefab != null)
                {
                    GameObject hitEffect = (GameObject)Instantiate(data.impactPrefab, transform.position, Quaternion.Euler(0, 0, data.directionAngle));
                    Destroy(hitEffect, 1);
                }
                totalHits--;
                if (totalHits <= 0)
                {
                    Destroy(gameObject);
                }
                isHit = .3f;
                transform.Translate(movement * -1 * Time.deltaTime);
            }
        }

        if (opHitBoxesScript.testCollision(transform.position, data.hitRadius))
        {
            //Vector3 newPos = transform.position + Vector3.back;
            if (data.impactPrefab != null)
            {
                GameObject hitEffect = (GameObject)Instantiate(data.impactPrefab, transform.position, Quaternion.Euler(0, 0, data.directionAngle));
                Destroy(hitEffect, 1);
            }
            totalHits--;
            if (totalHits <= 0)
            {
                Destroy(gameObject);
            }

            isHit = opControlsScript.GetFreezingTime(data.hitStrengh) * 1.2f;
            Hit hit = new Hit();
            hit.hitType        = data.hitType;
            hit.hitStrengh     = data.hitStrengh;
            hit.hitStunType    = HitStunType.Frames;
            hit.hitStunOnHit   = data.hitStunOnHit;
            hit.hitStunOnBlock = data.hitStunOnBlock;
            hit.damageOnHit    = data.damageOnHit;
            hit.damageType     = data.damageType;
            hit.resetPreviousHorizontalPush = true;
            hit.pushForce   = data.pushForce;
            hit.pullEnemyIn = new PullIn();
            hit.pullEnemyIn.enemyBodyPart = BodyPart.none;

            if (!opControlsScript.stunned && opControlsScript.isBlocking && opControlsScript.TestBlockStances(hit.hitType))
            {
                opControlsScript.GetHitBlocking(hit, 20, transform.position);
            }
            else if (opControlsScript.potentialParry > 0 && opControlsScript.TestParryStances(hit.hitType))
            {
                opControlsScript.GetHitParry(hit, transform.position);
            }
            else
            {
                opControlsScript.GetHit(hit, 30, Vector3.zero);
            }

            opControlsScript.CheckBlocking(false);
        }
    }