public void Move(MobMovement moveType) { Random rand = RandomProvider.Get(); switch (moveType) { case MobMovement.Patrol: // TODO: Grab move radius from metadata int moveDistance = rand.Next(0, MoveRange); short moveAngle = (short)rand.Next(-1800, 1800); Velocity = CoordF.From(moveDistance, moveAngle); // Keep near spawn if ((SpawnDistance - Velocity).Length() >= Block.BLOCK_SIZE * 2) { moveAngle = (short)SpawnDistance.XYAngle(); Velocity = CoordF.From(Block.BLOCK_SIZE, moveAngle); } ZRotation = moveAngle; // looking direction of the monster break; case MobMovement.Follow: // move towards target case MobMovement.Strafe: // move around target case MobMovement.Run: // move away from target case MobMovement.LookAt: case MobMovement.Hold: default: Velocity = CoordF.From(0, 0, 0); break; } SpawnDistance -= Velocity; }
public void Act() { if (AI == null) { return; } (string actionName, NpcAction actionType) = AI.GetAction(this); Animation = AnimationStorage.GetSequenceIdBySequenceName(Model, actionName); CurrentAction = actionType; CurrentMovement = AI.GetMovementAction(this); switch (CurrentAction) { case NpcAction.Idle: Move(MobMovement.Hold); // temp, maybe remove the option to specify movement in AI break; case NpcAction.Bore: Move(MobMovement.Hold); // temp, maybe remove the option to specify movement in AI break; case NpcAction.Walk: Move(CurrentMovement); break; case NpcAction.Jump: default: break; } }
public void Init(int selectedmenu) { b1.onClick.RemoveAllListeners(); b2.onClick.RemoveAllListeners(); b3.onClick.RemoveAllListeners(); b4.onClick.RemoveAllListeners(); b5.onClick.RemoveAllListeners(); b6.onClick.RemoveAllListeners(); b7.onClick.RemoveAllListeners(); b8.onClick.RemoveAllListeners(); b9.onClick.RemoveAllListeners(); b10.onClick.RemoveAllListeners(); b11.onClick.RemoveAllListeners(); if (selectedmenu == 1) { b1 = GameObject.FindGameObjectWithTag("Play").GetComponent <Button>(); b2 = GameObject.FindGameObjectWithTag("Options").GetComponent <Button>(); b1.onClick.AddListener(TaskOnClick1); b2.onClick.AddListener(TaskOnClick2); b9.onClick.AddListener(TaskOnClick9); script1 = GameObject.Find("Mobs").GetComponent <MobMovement>(); script2 = GameObject.Find("EndlessSpawner").GetComponent <EndlessSpawnerScript>(); script3 = GameObject.Find("Humans").GetComponent <HumanAI>(); script4 = GameObject.Find("BrainSpawner").GetComponent <BrainGenerator>(); script5 = GameObject.Find("Player").GetComponent <MovementScript>(); script6 = GameObject.Find("Main Camera").GetComponent <CameraController>(); } else if (selectedmenu == 2) { hiscoretext.text = "Hiscore: " + hiscore.ToString("D3"); b3 = GameObject.FindGameObjectWithTag("ResetScore").GetComponent <Button>(); b4 = GameObject.FindGameObjectWithTag("Dark").GetComponent <Button>(); b5 = GameObject.FindGameObjectWithTag("Light").GetComponent <Button>(); b6 = GameObject.FindGameObjectWithTag("Return").GetComponent <Button>(); b3.onClick.AddListener(TaskOnClick3); b4.onClick.AddListener(TaskOnClick4); b5.onClick.AddListener(TaskOnClick5); b6.onClick.AddListener(TaskOnClick6); } else if (selectedmenu == 3) { b7 = GameObject.FindGameObjectWithTag("Retry").GetComponent <Button>(); b8 = GameObject.FindGameObjectWithTag("Exit").GetComponent <Button>(); b7.onClick.AddListener(TaskOnClick7); b8.onClick.AddListener(TaskOnClick8); } else if (selectedmenu == 4) { b10 = GameObject.FindGameObjectWithTag("Return").GetComponent <Button>(); b10.onClick.AddListener(TaskOnClick10); } }
public void Act() { if (AI == null) { return; } (string actionName, NpcAction actionType) = AI.GetAction(this); if (actionName != null) { Animation = AnimationStorage.GetSequenceIdBySequenceName(Value.Model, actionName); } Action = actionType; Movement = AI.GetMovementAction(this); switch (Action) { case NpcAction.Idle: case NpcAction.Bore: Move(MobMovement.Hold); // temp, maybe remove the option to specify movement in AI break; case NpcAction.Walk: case NpcAction.Run: Move(Movement); break; case NpcAction.Skill: // Cast skill if (!OnCooldown) { Attack(); Move(MobMovement.Hold); break; } Move(Movement); break; case NpcAction.Jump: default: break; } }
public void Init(bool started) { ms = GameObject.FindGameObjectWithTag("Player").GetComponent <MovementScript>(); mobscript = GameObject.Find("Mobs").GetComponent <MobMovement>(); gs = GameObject.FindGameObjectWithTag("Canvas").GetComponent <GameStart>(); ha = GameObject.Find("Humans").GetComponent <HumanAI>(); hitsource = GameObject.Find("HitSound").GetComponent <AudioSource>(); brainsource = GameObject.Find("BrainSound").GetComponent <AudioSource>(); humandeathsource = GameObject.Find("HumanDeathSound").GetComponent <AudioSource>(); zombiedeathsource = GameObject.Find("ZombieDeathSound").GetComponent <AudioSource>(); mobsource = GameObject.Find("MobSound").GetComponent <AudioSource>(); hitsource.clip = hitaudio; brainsource.clip = brainaudio; humandeathsource.clip = humandeathaudio; zombiedeathsource.clip = zombiedeathaudio; control = GetComponent <CharacterController>(); anim = GetComponent <Animator>(); begin = true; }
private static void ParseAI(XmlDocument document) { XmlNode behaviorsNode = document.SelectSingleNode("/ai/behavior"); MobAI ai = new MobAI(); foreach (XmlNode node in behaviorsNode) { NpcState stateValue = GetMobState(node.Name); NpcAction newActionValue = GetMobAction(node.Attributes["action"]?.Value); MobMovement movementValue = GetMobMovement(node.Attributes["movement"]?.Value); MobAI.Condition[] conditions = GetConditions(/*node*/); ai.Rules.TryAdd(stateValue, (newActionValue, movementValue, Array.Empty <MobAI.Condition>())); } string aiName = document.BaseURI.Split("MobAI/")[1]; AiTable.Add(aiName, ai); }
void OnEnable() { MyTarget = target as MobMovement; if (MyTarget.Animator == null) MyTarget.Animator = MyTarget.GetComponent<Animator>(); if (MyTarget.Agent == null) MyTarget.Agent = MyTarget.GetComponent<NavMeshAgent>(); MyTarget.GetComponent<SphereCollider>().isTrigger = true; MyTarget.gameObject.layer = 13; }
public void Detected(MobMovement mob, Transform target) { mob.Follow(target); }
// Use this for initialization void Awake() { myMobMovement = GetComponent <MobMovement> (); myAnimator = GetComponent <Animator> (); }
// Update is called once per frame void Update() { if (networkView.isMine) { if (/*myMobMovement.isAttacking &&*/ myAnimator.GetCurrentAnimatorStateInfo(0).IsName("Attack")) { myMobMovement.timerBetweenAttacks = 0f; } else { myMobMovement.timerBetweenAttacks += Time.deltaTime; } if (myAnimator.GetCurrentAnimatorStateInfo(0).IsName("Death") && myAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 0.9f) { GetComponent <HealthManager>().deathAnimationFinished = true; } // if (GetComponent<HealthManager>().isTakingDamage) { // if (GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName("ReceiveDamage")) { // GetComponent<Animator> ().SetBool ("receiveDamage", false); // GetComponent<HealthManager>().isTakingDamage = false; // receiveDamage = false; // networkView.RPC ("UpdateReceiveDamage", RPCMode.All, false); // } // else { // GetComponent<Animator>().speed = 1; // GetComponent<Animator> ().SetBool ("receiveDamage", true); // receiveDamage = true; // networkView.RPC ("UpdateReceiveDamage", RPCMode.All, true); // } // } if (GetComponent <HealthManager>().isDead) { GetComponent <Animator> ().SetBool("isDead", true); isDead = true; networkView.RPC("UpdateIsDead", RPCMode.All, true); } if (GetComponent <MobMovement>().isAttacking&& !GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Attack") && myMobMovement.timerBetweenAttacks >= myMobMovement.timeBetweenAttacksInSeconds) { GetComponent <Animator> ().SetBool("isAttacking", true); GetComponent <MobMovement>().isAttacking = false; isAttacking = true; networkView.RPC("UpdateIsAttacking", RPCMode.All, true); } else if (GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Attack")) { //myMobMovement.isAttacking = false; GetComponent <Animator> ().SetBool("isAttacking", false); isAttacking = false; networkView.RPC("UpdateIsAttacking", RPCMode.All, false); } Animator animator = GetComponent <Animator> (); MobMovement mobMovement = GetComponent <MobMovement> (); speed = (rigidbody.velocity - new Vector3(0, rigidbody.velocity.y, 0)).magnitude; if (mobMovement.targetAquired && speed > 0.25f) { animator.SetBool("investigate", false); animator.SetBool("chase", true); investigate = false; chase = true; networkView.RPC("UpdateInvestigate", RPCMode.All, false); networkView.RPC("UpdateChase", RPCMode.All, true); } else if (mobMovement.isSuspicious && speed > 0.25f) { animator.SetBool("investigate", true); animator.SetBool("chase", false); investigate = true; chase = false; networkView.RPC("UpdateInvestigate", RPCMode.All, true); networkView.RPC("UpdateChase", RPCMode.All, false); } else { animator.SetBool("investigate", false); animator.SetBool("chase", false); investigate = false; chase = false; networkView.RPC("UpdateInvestigate", RPCMode.All, false); networkView.RPC("UpdateChase", RPCMode.All, false); } } else { //networkView.RPC ("UpdateAnimation", RPCMode.All, investigate, chase, isAttacking, receiveDamage, isDead); } }