// Run from the player, also plays sound at this point. public void Run() { mMover.mCanUsePath = false; // if we're not already charging, set our state to charging if (!mIsFleeing) { string[] args = new string[] { "Grunt", "Cower" }; AUD_Manager.DynamicDialogue("VO_Negatives_E", args, gameObject); mAnim.mState = AnimState.FLEEING; mIsFleeing = true; mTimeStartedFlee = Time.time; // set the goal to somewhere behind the player. Vector3 dir = transform.position - mEntity.mPlayerTrans.Value.position; dir.y = 0f; Vector3 spot = transform.position + Vector3.Normalize(dir) * 100f; mEntity.mGoalPos = spot; } mEntity.mCurMaxVel = mEntity.GetBase().mMaxSpd * 1.2f; mRigid.rotation = mOrienter.OrientToDirection(mRigid.velocity); // handle if the flee state has finished. if (Time.time - mTimeStartedFlee > mEntity.GetBase().mFleeTime.Value) { mMover.mCanUsePath = true; mIsFleeing = false; mCanFlee = false; Invoke("CanFlee", 0.2f); mAnim.mState = AnimState.IDLE; } }
public void Run() { // spawn hitbox, double velocity, do other stuff mCannon.mState = CANNON_STATE.INACTIVE; // if we're not already charging, set our state to charging if (!mIsCharging) { mIsCharging = true; mTimeStartedCharge = Time.time; // set the goal to somewhere behind the player. Vector3 dir = mEntity.mPlayerTrans.Value.position - transform.position; dir.y = 0f; dir = Vector3.Normalize(dir); mCachedDir = dir; Vector3 spot = transform.position + Vector3.Normalize(dir) * 10f; Debug.DrawLine(transform.position, spot, Color.black, 5f); mEntity.mGoalPos = spot; mMeleeHitBox.gameObject.SetActive(true); mAnim.mState = AnimState.CHARGING; } // ugh. Gotta do some manual velocity LERPing here. mEntity.mCurMaxVel = mEntity.GetBase().mMaxSpd * 2.5f; float tmStartsSlowing = 1.1f; if (Time.time - mTimeStartedCharge > tmStartsSlowing) { float tmSinceStart = Time.time - mTimeStartedCharge; float tmAfterStartedSlowing = tmSinceStart - tmStartsSlowing; float tmToZero = mEntity.GetBase().mChargeTime.Value - tmStartsSlowing; float percent = 1f - (tmAfterStartedSlowing / tmToZero); mEntity.mCurMaxVel *= percent; } mRigid.rotation = mOrienter.OrientToDirection(mCachedDir); // handle if the charge has finished. if (Time.time - mTimeStartedCharge > mEntity.GetBase().mChargeTime.Value) { mIsCharging = false; mCanCharge = false; Invoke("CanCharge", 1.1f); mMeleeHitBox.gameObject.SetActive(false); } }
// Lots of side effects. May have to make one that doesn't have master tell us to fire. public void Run() { float dis = Vector3.Distance(mEntity.mPlayerTrans.Value.position, transform.position); bool doStrafe = false; if (dis < mGun.mGunProperties.mRange * 0.8f && mCons.mCanSeePlayer && mWasWithinRange) { doStrafe = true; } if (dis < mGun.mGunProperties.mRange && mCons.mCanSeePlayer) { doStrafe = true; } if (doStrafe) { // now we strafe and stuff. mRigid.rotation = mOrienter.OrientToSpot(mEntity.mPlayerTrans.Value.position); if (Vector3.Distance(transform.position, mEntity.mPlayerTrans.Value.position) < mEntity.GetBase().mAlwaysFireRange) { mGun.TryToFireGun(mEntity.mPlayerTrans.Value); } else { mEntity.mMaster.ThisEnemyWantsToFire(mEntity); } // now we have to check if we're really close. Let's say within 5f meters for now. Eventually, put this in as a back up range in SO_AI_Base. // If so, we move backwards, and animate for backwards. if (dis < 5f) { Vector3 dir = transform.position - mEntity.mPlayerTrans.Value.position; dir = Vector3.Normalize(dir); mEntity.mGoalPos = transform.position + dir * 10f; mAnim.mState = AnimState.BACKING_UP; mEntity.mCurMaxVel = mEntity.GetBase().mMaxSpd * 0.5f; return; } // we get the enemies to slowly move side to side when in range. if (mStrafer.NeedsNewStrafeSpot()) { mEntity.mGoalPos = mStrafer.FindStrafeSpot(); } mEntity.mCurMaxVel = mEntity.GetBase().mMaxSpd * 0.4f; // eventually set us to strafing. For now, just set us to idle. // Actually, we have to figure out if we're strafing left or right. float dot = Vector3.Dot(transform.right, (mEntity.mGoalPos - transform.position)); if (dot > 0f) { // means we're going to our right. mAnim.mState = AnimState.STRAFING_RIGHT; } else { mAnim.mState = AnimState.STRAFING_LEFT; } } else { // now we just try to move to the player. mEntity.mGoalPos = mEntity.mPlayerTrans.Value.position; mEntity.mCurMaxVel = mEntity.GetBase().mMaxSpd; mRigid.rotation = mOrienter.OrientToDirection(mRigid.velocity); mAnim.mState = AnimState.MOVING_FORWARD; } }