// 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); } }
private Vector3 CalculateRandomError(Vector3 dir) { AI_Controller owner = UT_FindComponent.FindComponent <AI_Controller>(gameObject); if (owner == null) { return(dir); } SO_AI_Base bs = owner.GetBase(); if (!bs.mFireInaccurately) { return(dir); } // now find a random spread up to the max spread. float spread = Random.Range(0, bs.mInacRange); if (Random.value > 0.5f) { spread *= -1; } // now apply that spread to the bullets direction. Vector3 newDir = Quaternion.AngleAxis(spread, Vector3.up) * dir; return(newDir); }
public void Run() { mRigid.constraints = RigidbodyConstraints.None; // mAnim.mState = AnimState.FLYING; // after a certain amount of time, switch states back to combat // before that, let us handle collisions again. float timePassed = Time.time - mTimeStartedFlying; // If they have been flying for > 4 seconds, then just kill them. if (timePassed > 4f) { mEntity.TakeDamage(100000000000f); Debug.Log("Killed because flying too long"); return; } if (timePassed > 0.05f) { mRigid.detectCollisions = true; } if (timePassed > mEntity.GetBase().mTimeFly) { mEntity.mStateChange = STATE.COMBAT; } // make them tumble in the air. mModelFollower.rotateSpeed = 100000000000f; Vector3 rot = transform.rotation.eulerAngles; rot.x += mRotSpeed.Value.x; rot.y += mRotSpeed.Value.y; rot.z += mRotSpeed.Value.z; transform.rotation = Quaternion.Euler(rot); }
private void Update() { // first set health bar length. float percent = mOwner.GetHealth() / mOwner.GetBase().mMaxHealth; mBarImg.fillAmount = percent; }
private void Fire() { mFireTimeStamp = Time.time; Vector3 dir = Vector3.Normalize(mVictim.position - transform.position); GameObject clone; bool red = (Random.value < 0.5); if (red) { clone = Instantiate(mCannonProperties.mRedBullet, mFirePoint.position, Quaternion.LookRotation(dir, Vector3.up)); } else { clone = Instantiate(mCannonProperties.mBlueBullet, mFirePoint.position, Quaternion.LookRotation(dir, Vector3.up)); } clone.GetComponent <Bullet>().SetOwner(mEntity.transform); clone.GetComponent <Bullet>().SetTarget(mVictim); Instantiate(mGunProperties.mMuzzleBlast, mFirePoint.transform.position, transform.rotation); AUD_Manager.PostEvent(mGunProperties.mAudFireEvent, gameObject); AUD_Manager.DynamicDialogueFromData(mEntity.GetBase().mShootLine, gameObject); mEntity.GetBase().mEnemyFired.Raise(null); // Tank cannon specific stuff. mNumFiredThisVolley++; if (mNumFiredThisVolley == mCannonProperties.mNumInVolley) { mState = CANNON_STATE.CHARGING; mCurChargeAmt = 0f; mNumFiredThisVolley = 0; } else { mState = CANNON_STATE.PREFIRE; mCurChamberAmt = 0f; } }
/************************************************************************************************ * Each individual weapon will define how it fires its projectile. * By the time this has been called we are sure that we are firing the weapon. We have already checked * that we are loaded, charged, and nothing else is preventing us from firing. * * Great opportunity to use Carlos's Event system. ************************************************************************************************/ protected virtual void FireProjectile(Transform trans) { mFireTimeStamp = Time.time; // our plasma ray gun is as basic as it gets, spawning a plasmoid and then trying to re-chamber. // The target has already been set, and the projectile now simply has to have force added in the direction Vector3 dir = Vector3.Normalize(trans.position - transform.position); // GameObject clone = PhotonNetwork.Instantiate(mGunProperties.bullet.name, transform.position, Quaternion.LookRotation(dir, Vector3.up)); dir = CalculateRandomError(dir); GameObject clone = Instantiate(mRegGunProperties.bullet, firePoint.position, Quaternion.LookRotation(dir, Vector3.up)); AI_Controller owner = UT_FindComponent.FindComponent <AI_Controller>(gameObject); if (owner != null) { clone.GetComponent <Bullet>().SetOwner(owner.transform); } else { clone.GetComponent <Bullet>().SetOwner(transform); } clone.GetComponent <Bullet>().SetTarget(trans); // Also, got to create those particles for the muzzle blast if (mGunProperties.mMuzzleBlast) { var mBlast = Instantiate(mGunProperties.mMuzzleBlast, firePoint.transform.position, transform.rotation); } for (int i = 0; i < mGunProperties.mSwitchGroups.Length; i++) { AUD_Manager.SetSwitch(mGunProperties.mSwitchGroups[i], mGunProperties.mSwitchStates[i], gameObject); } AUD_Manager.PostEvent(mGunProperties.mAudFireEvent, gameObject); // play the dialogue for our character shooting. AUD_Manager.DynamicDialogueFromData(owner.GetBase().mShootLine, gameObject); // Now push the event that a weapon has fired. owner.GetBase().mEnemyFired.Raise(null); }
private float CalcStunLeft() { // after a certain amount of time, switch states back to combat float timePassed = Time.time - mGrenLogic.mTimeHitGrenade; float normTimeLeft = 1f - (timePassed / mEntity.GetBase().mTimeInGrenadeStun); if (normTimeLeft < 0f) { normTimeLeft = 0f; } return(normTimeLeft); }
public void Run() { mAnim.mState = AnimState.GROSSED_OUT; mRigid.constraints = RigidbodyConstraints.FreezeAll; mRigid.velocity = Vector3.zero; // after a certain amount of time, switch states back to combat float timePassed = Time.time - mTimeHitGrenade; if (timePassed > mEntity.GetBase().mTimeInGrenadeStun) { mEntity.mStateChange = STATE.COMBAT; mStunParticles.Deactivate(); } }
private void Awake() { mOwner = GetComponent <AI_Controller>(); mGrenadedLogic = GetComponent <AI_GrenadedLogic>(); mStunParticles = GetComponentInChildren <StunnedParticles>(); mStunParticles.Deactivate(); switch (mOwner.GetBase().mType) { case EnemyTypes.GRUNT: sType = "Grunt"; break; case EnemyTypes.LANKY: sType = "Lanky"; break; case EnemyTypes.TANK: sType = "Tank"; break; } }
// 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; } }