private void getPlayerPos() { playerPos = GameObject.Find("Player").GetComponent <Rigidbody>().position; // compute 45 degrees from player ship if (this.transform.position.y >= 0) { targetX.x = playerPos.x + (9.5f - playerPos.y); // since we seek a 45d angle, dY = dX } else { targetX.x = playerPos.x + (playerPos.y + 7); } // send the player towards this landmark if (this.transform.position.x >= targetX.x) { enemyRigid.velocity = new Vector3(-seekSpeed, 0, 0); } else { enemyRigid.velocity = new Vector3(seekSpeed, 0, 0); } thisStatus = ATSTstatus.seeking; }
public override void Move() { // set ATST actions if (thisStatus == ATSTstatus.seeking) { // check to see if enemy reached its landmark within +/-0.1 if (this.transform.position.x < targetX.x + 0.25 && this.transform.position.x > targetX.x - 0.25) { enemyRigid.velocity = new Vector3(-speed, 0, 0); startDelay = Time.time; thisStatus = ATSTstatus.firing; } } else if (thisStatus == ATSTstatus.firing && Time.time - startDelay > shotDelay) { // if the delay in shotDelay has passed shotCnt++; if (shotCnt > maxShots) { thisStatus = ATSTstatus.leaving; enemyRigid.velocity = new Vector3(-seekSpeed, 0, 0); } else if (Random.value < fireChance) { Fire(); startDelay = Time.time; thisStatus = ATSTstatus.chill; } else { getPlayerPos(); thisStatus = ATSTstatus.seeking; } } else if (thisStatus == ATSTstatus.chill && Time.time - startDelay > chillDelay) { thisStatus = ATSTstatus.seeking; getPlayerPos(); // restart the cycle } else if (thisStatus == ATSTstatus.leaving) { } if (thisStatus != ATSTstatus.seeking && thisStatus != ATSTstatus.leaving) { anim.SetFloat("speed", 0); } else { anim.SetFloat("speed", this.enemyRigid.velocity.x); } }