コード例 #1
0
    private void HandleAttack()
    {
        Vector3 attackDir = animatedWalker.GetLastMoveVector();

        if (Input.GetMouseButtonDown(0))
        {
            attackDir = (UtilsClass.GetMouseWorldPosition() - GetPosition()).normalized;
        }

        if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0))
        {
            // Attack
            SetStateBusy();

            EnemyHandler enemyHandler = EnemyHandler.GetClosestEnemy(GetPosition() + attackDir * 4f, 20f);
            if (enemyHandler != null)
            {
                enemyHandler.Damage(this);
                attackDir          = (enemyHandler.GetPosition() - GetPosition()).normalized;
                transform.position = enemyHandler.GetPosition() + attackDir * -12f;
            }
            else
            {
                transform.position = transform.position + attackDir * 4f;
            }

            /*
             * unitAnimation.PlayAnimForced(UnitAnimType.GetUnitAnimType("dBareHands_PunchStartup"), attackDir, 2f, (UnitAnim unitAnim) => {
             *  unitAnimation.PlayAnimForced(UnitAnimType.GetUnitAnimType("dBareHands_PunchQuickAttack"), attackDir, 1f, (UnitAnim unitAnim2) => SetStateNormal(), null, null);
             * }, null, null);
             */

            UnitAnimType activeAnimType = unitAnimation.GetActiveAnimType();
            switch (activeAnimType.GetName())
            {
            default:
                unitAnimation.PlayAnimForced(UnitAnimType.GetUnitAnimType("dBareHands_PunchQuick"), attackDir, 1f, (UnitAnim unitAnim2) => SetStateNormal(), null, null);
                break;

            case "dBareHands_PunchQuick":
                unitAnimation.PlayAnimForced(UnitAnimType.GetUnitAnimType("dBareHands_KickQuick"), attackDir, 1f, (UnitAnim unitAnim2) => SetStateNormal(), null, null);
                break;
            }

            //unitAnimation.PlayAnimForced(UnitAnimType.GetUnitAnimType("dBareHands_PunchQuickAttack"), attackDir, 1f, (UnitAnim unitAnim2) => SetStateNormal(), null, null);

            /*
             * Transform swordSlashTransform = Instantiate(GameAssets.i.pfSwordSlash, GetPosition() + attackDir * 13f, Quaternion.Euler(0, 0, UtilsClass.GetAngleFromVector(attackDir)));
             * swordSlashTransform.GetComponent<SpriteAnimator>().onLoop = () => Destroy(swordSlashTransform.gameObject);
             *
             * UnitAnimType activeAnimType = unitAnimation.GetActiveAnimType();
             * if (activeAnimType == GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword) {
             *  swordSlashTransform.localScale = new Vector3(swordSlashTransform.localScale.x, swordSlashTransform.localScale.y * -1, swordSlashTransform.localScale.z);
             *  unitAnimation.PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword2, attackDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null);
             * } else {
             *  unitAnimation.PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword, attackDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null);
             * }
             */
        }
    }
コード例 #2
0
    private void FindTarget()
    {
        float targetRange = 100f;
        float attackRange = 15f;

        if (getEnemyTarget != null)
        {
            if (Vector3.Distance(getEnemyTarget().GetPosition(), GetPosition()) < attackRange)
            {
                StopMoving();
                state = State.Busy;
                unitAnimation.PlayAnimForced(attackUnitAnim, 1f, (UnitAnim unitAnim) => {
                    // Attack complete
                    state = State.Normal;
                }, (string trigger) => {
                    // Damage Player
                    getEnemyTarget().Damage(this);
                }, null);
            }
            else
            {
                if (Vector3.Distance(getEnemyTarget().GetPosition(), GetPosition()) < targetRange)
                {
                    if (pathfindingTimer <= 0f)
                    {
                        pathfindingTimer = .3f;
                        SetTargetPosition(getEnemyTarget().GetPosition());
                    }
                }
            }
        }
    }
コード例 #3
0
    private void AttackPlayer()
    {
        StopMoving();
        state = State.Busy;

        Vector3 targetPosition = getEnemyTarget().GetPosition();
        Vector3 dirToTarget    = (targetPosition - GetPosition()).normalized;

        unitAnimation.PlayAnimForced(attackUnitAnim, dirToTarget, 2f, (UnitAnim unitAnim) => {
            // Attack complete
            if (getEnemyTarget().IsDead())
            {
                state = State.Normal;
            }
            else
            {
                state = State.AttackingPlayer;
            }
        }, (string trigger) => {
            // Damage Player
            getEnemyTarget().Damage(this);
        }, null);

        Vector3 gunEndPointPosition = unitSkeleton.GetBodyPartPosition("MuzzleFlash");

        Shoot_Flash.AddFlash(gunEndPointPosition);
        WeaponTracer.Create(gunEndPointPosition, getEnemyTarget().GetPosition());
    }
コード例 #4
0
        private void HandleAttack()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                // Attack
                SetStateBusy();

                Vector3      attackDir    = lastMoveDir;
                EnemyHandler enemyHandler = getClosestEnemyHandlerFunc(GetPosition() + attackDir * 4f);
                if (enemyHandler != null)
                {
                    // Has a target nearby
                    attackDir = (enemyHandler.GetPosition() - GetPosition()).normalized;
                    // Test if too close to dash
                    const float tooCloseToDashDistance = 10f;
                    if (Vector3.Distance(enemyHandler.GetPosition(), GetPosition()) > tooCloseToDashDistance)
                    {
                        // Dash towards attack distance
                        transform.position = transform.position + attackDir * 4f;
                    }
                    // Is enemy within attack range?
                    const float attackDistance = 30f;
                    if (Vector3.Distance(enemyHandler.GetPosition(), GetPosition()) < attackDistance)
                    {
                        // Close enough to damage
                        enemyHandler.GetHealthSystem().Damage(34);
                        Blood_Handler.SpawnBlood(enemyHandler.GetPosition(), attackDir);
                    }
                }
                else
                {
                    // No nearby target
                    transform.position = transform.position + attackDir * 4f;
                }
                lastMoveDir = attackDir;

                Transform swordSlashTransform = Instantiate(GameAssets.i.pfSwordSlash, GetPosition() + attackDir * 13f, Quaternion.Euler(0, 0, UtilsClass.GetAngleFromVector(attackDir)));
                swordSlashTransform.GetComponent <SpriteAnimator>().onLoop = () => Destroy(swordSlashTransform.gameObject);

                UnitAnimType activeAnimType = unitAnimation.GetActiveAnimType();
                if (activeAnimType == GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword)
                {
                    swordSlashTransform.localScale = new Vector3(swordSlashTransform.localScale.x, swordSlashTransform.localScale.y * -1, swordSlashTransform.localScale.z);
                    unitAnimation.PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword2, lastMoveDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null);
                }
                else
                {
                    unitAnimation.PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword, lastMoveDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null);
                }
            }
        }
コード例 #5
0
 public void PlayPunchAnimation(Vector3 dir, Action <Vector3> onHit, Action onAnimComplete)
 {
     unitAnimation.PlayAnimForced(UnitAnimType.GetUnitAnimType("dBareHands_PunchQuick"), dir, 1f, (UnitAnim unitAnim2) => {
         if (onAnimComplete != null)
         {
             onAnimComplete();
         }
     }, (string trigger) => {
         // HIT = HandR
         // HIT2 = HandL
         string hitBodyPartName = trigger == "HIT" ? "HandR" : "HandL";
         Vector3 impactPosition = unitSkeleton.GetBodyPartPosition(hitBodyPartName);
         if (onHit != null)
         {
             onHit(impactPosition);
         }
     }, null);
 }
コード例 #6
0
    private void Start()
    {
        Transform bodyTransform = transform.Find("Body");

        unitSkeleton  = new V_UnitSkeleton(1f, bodyTransform.TransformPoint, (Mesh mesh) => bodyTransform.GetComponent <MeshFilter>().mesh = mesh);
        unitAnimation = new V_UnitAnimation(unitSkeleton);

        idleUnitAnim   = GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Idle;
        walkUnitAnim   = GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Walk;
        hitUnitAnim    = null;
        attackUnitAnim = null;

        idleUnitAnim   = UnitAnimType.GetUnitAnimType("dBareHands_Idle");
        walkUnitAnim   = UnitAnimType.GetUnitAnimType("dBareHands_Walk");
        hitUnitAnim    = UnitAnimType.GetUnitAnimType("dBareHands_Hit");
        attackUnitAnim = UnitAnimType.GetUnitAnimType("dBareHands_PunchQuickAttack");

        animatedWalker = new AnimatedWalker(unitAnimation, idleUnitAnim, walkUnitAnim, 1f, .75f);

        state = State.Normal;

        FunctionTimer.Create(() => unitAnimation.PlayAnimForced(UnitAnim.GetUnitAnim("dBareHands_JumpRight"), 1f, null), 2f);
    }
コード例 #7
0
 public void PlayPunchAnimation(Vector3 dir, Action <Vector3> onHit, Action onAnimComplete, float frameRateMod = 1f)
 {
     if (axis == Axis.XZ && dir.y == 0f)
     {
         dir = new Vector3(dir.x, dir.z);
     }
     unitAnimation.PlayAnimForced(UnitAnimType.GetUnitAnimType("dBareHands_PunchQuick"), dir, 1f, (UnitAnim unitAnim2) => {
         if (onAnimComplete != null)
         {
             onAnimComplete();
         }
     }, (string trigger) => {
         // HIT = HandR
         // HIT2 = HandL
         string hitBodyPartName = trigger == "HIT" ? "HandR" : "HandL";
         Vector3 impactPosition = unitSkeleton.GetBodyPartPosition(hitBodyPartName);
         if (onHit != null)
         {
             onHit(impactPosition);
         }
     }, null);
 }
コード例 #8
0
 public void PlayDodgeAnimation(Vector3 dir)
 {
     unitAnimation.PlayAnimForced(UnitAnimType.GetUnitAnimType("dBareHands_Roll"), dir, 1.5f, null, null, null);
 }
コード例 #9
0
 public void PlayAnimSlideRight()
 {
     unitAnimation.PlayAnimForced(UnitAnim.GetUnitAnim("dBareHands_SlideRight"), 1f, null);
 }