private void Chase(BasicStateMachine controller) { AStateController ncon = (AStateController)controller; float speed = ncon.values.speed.x * Time.fixedDeltaTime; // * ncon.moveDirection; if (ncon.useSlowTime.value && !ncon.slowSoldierSide.value) { speed *= ncon.slowAmount.value; } ncon.movement = Vector2.MoveTowards(ncon.thisTransform.position, ncon.aPlayer.position, speed); ncon.movement = ncon.moveBounds.bounds.ClosestPoint(ncon.movement); ncon.rigidBody.MovePosition(ncon.movement); if (ncon.thisTransform.position.x < ncon.aPlayer.position.x) { ncon.moveDirection = 1; } else { ncon.moveDirection = -1; } }
private void Flee(BasicStateMachine controller) { AStateController ncon = (AStateController)controller; float speed = Time.fixedDeltaTime; // * ncon.moveDirection; if (ncon.useSlowTime.value && !ncon.slowSoldierSide.value) { speed *= ncon.slowAmount.value; } Vector2 direction = ncon.thisTransform.position - ncon.aPlayer.position; ncon.movement = new Vector2(ncon.thisTransform.position.x, ncon.thisTransform.position.y) + (new Vector2(direction.normalized.x * ncon.values.speed.x, direction.normalized.y * ncon.values.speed.y) * speed); ncon.movement = ncon.moveBounds.bounds.ClosestPoint(ncon.movement); ncon.rigidBody.MovePosition(ncon.movement); if (ncon.thisTransform.position.x < ncon.aPlayer.position.x) { ncon.moveDirection = -1; } else { ncon.moveDirection = 1; } }
public override bool Decide(BasicStateMachine controller) { AStateController ncon = (AStateController)controller; if (controller.stateTimeElapsed >= ncon.values.chaseTimeLimit) { return(true); } return(false); }
public override bool Decide(BasicStateMachine controller) { AStateController acon = (AStateController)controller; float dist = Vector2.Distance(acon.aPlayer.position, acon.thisTransform.position); if (dist <= acon.values.meleeRange) { acon.hasAttacked = false; return(true); } return(false); }
public override bool Decide(BasicStateMachine controller) { AStateController acon = (AStateController)controller; float dist = Vector2.Distance(acon.aPlayer.position, acon.thisTransform.position); if (dist <= acon.thisTransform.localScale.x / 2 + 0.1f) { // Debug.Log("Hit the player"); return(true); } return(false); }
public override bool Decide(BasicStateMachine controller) { AStateController ncon = (AStateController)controller; float dist = Vector2.Distance(ncon.aPlayer.position, ncon.thisTransform.position); if (dist > 3.0f) { controller.hasAttacked = false; return(true); } return(false); }
public override void Attack(StateController controller, AttackScript attackScript) { if (!(controller is AStateController)) { Debug.LogError("Wrong controller user!"); return; } AStateController ncon = (AStateController)controller; var shotTransform = Instantiate(attackScript.projectile) as Transform; Projectile projectile = shotTransform.GetComponent <Projectile>(); shotTransform.position = ncon.thisTransform.position; MouseInformation info = new MouseInformation(); info.position1 = controller.thisTransform.position; info.setPosition2(controller.aPlayer.position); if (setRotation) { float rotation = info.rotationInternal * 180 / Mathf.PI; shotTransform.localRotation = Quaternion.AngleAxis(rotation, Vector3.forward); } projectile.isEnemy = true; projectile.multiHit = attackScript.multihit; projectile.SetDamage(attackScript.damage, 0, 1); projectile.impactSound = controller.values.attackImpactSfx; projectile.SetMovement(attackScript.speed, info.rotationInternal); attackScript.bgui.effectList.Add(projectile); if (controller.values.attackActivateSfx != null) { controller.currentSfx.value.Enqueue(controller.values.attackActivateSfx.clip); controller.playSfxEvent.Invoke(); } }
/// <summary> /// Creates an enemy for the android side of the battlefield. /// </summary> /// <param name="values"></param> /// <param name="group"></param> /// <param name="index"></param> private void CreateA(EnemyEntry values, EnemyGroup group) { if (!spawnBottom) { return; } ggobjA = Instantiate(values.enemyModelN) as Transform; AStateController state = ggobjA.GetComponent <AStateController>(); HurtableEnemyScript hurt = ggobjA.GetComponent <HurtableEnemyScript>(); AttackScript attack = ggobjA.GetComponent <AttackScript>(); hurt.group = group; state.enemyid = enemyId; state.values = ScriptableObject.CreateInstance <EnemyEntry>(); state.values.CopyValues(values); state.moveBounds = aMoveBounds; ggobjA.position = state.GetRandomLocation(); group.bot = hurt; group.nStateController = state; group.nTransform = ggobjA; group.nAttackScript = attack; }