// Update is called once per frame void Update() { if (Mathf.Abs(transform.rotation.z) > 40) { transform.rotation = new Quaternion(0f, 0f, 0f, 0f); transform.position += new Vector3(0.0f, 1.0f, 0.0f); } running = false; grounded = true; attackTimer += Time.deltaTime; jumpTimer += Time.deltaTime; damageTimer += Time.deltaTime; if (mTarget != null) { if (mTarget.position.x > transform.position.x) { facingDirection = Vector2.right; GetComponent <SpriteRenderer>().flipX = false; } else { facingDirection = Vector2.left; GetComponent <SpriteRenderer>().flipX = true; } if (damageTimer > 1) { hit = false; } if (attackTimer > 0.3) { shooting = false; } distance = Vector2.Distance(mTarget.position, this.transform.position); if (distance < 9 && distance > 6 && !hit) { transform.Translate(facingDirection * followSpeed * Time.deltaTime, Space.World); running = true; } if (distance < 8) { if (attackTimer > 2 && !hit) { shooting = true; attackTimer = 0; GameObject mb = Instantiate(mBullet, transform.position, Quaternion.identity) as GameObject; KiBlast blast = mb.GetComponent <KiBlast>(); mb.GetComponent <TimedExpiration>().mExpirationTime = 4; blast.setDirection(facingDirection); } } } UpdateAnimator(); }
public void Follow(Transform target) { if (target != null) { Vector2 targetPos = target.transform.position; Vector2 pos = transform.position; Vector2 direction = targetPos - pos; if (direction.magnitude <= mFollowRange) { if (direction.magnitude > mArriveThreshold) { mRunning = true; mAttacking = false; Vector2 newPos = (Vector2)(new Vector2(transform.position.x, 0)) + (new Vector2(direction.normalized.x * Time.deltaTime * mFollowSpeed, 0)); //mRigidBody2D.MovePosition(newPos); transform.Translate(new Vector2(direction.normalized.x, 0) * mFollowSpeed * Time.deltaTime, Space.World); } else { mRunning = false; if (attackTimer > 2) { mAttacking = true; UpdateAnimator(); attackTimer = 0; GameObject kB = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject; KiBlast blast = kB.GetComponent <KiBlast>(); Vector2 bDirection = mTarget.position - transform.position; bDirection.Normalize(); blast.setDirection(bDirection); } //transform.position = target.transform.position; } if (mTarget.position.x > transform.position.x) { GetComponent <SpriteRenderer>().flipX = false; } else { GetComponent <SpriteRenderer>().flipX = true; } } else { mAttacking = false; mRunning = false; } } }
void attack() { attacking = true; flying = false; UpdateAnimator(); GameObject kB = Instantiate(kiBlast, transform.position, Quaternion.identity) as GameObject; KiBlast blast = kB.GetComponent <KiBlast>(); Vector2 bDirection = mTarget.position - transform.position; bDirection.Normalize(); blast.setDirection(bDirection); }
// Update is called once per frame void Update() { comboTimer += Time.deltaTime; idleTimer += Time.deltaTime; if (mTarget != null) { distance = Vector3.Distance(mTarget.position, transform.position); // Sprite faces player if (mTarget.position.x > transform.position.x) { facingDirection = Vector2.right; GetComponent <SpriteRenderer>().flipX = false; } else { facingDirection = Vector2.left; GetComponent <SpriteRenderer>().flipX = true; } hit = false; attacking = false; if (!engaging && distance < 14) { engaging = true; } if (wounded) { if (blastDir.x < -2.0) { wounded = false; } else if (Mathf.Abs(transform.position.x - mTarget.position.x) > 0.5f && !combo) { Vector3 direction = new Vector3(mTarget.position.x, mTarget.position.y + 6.0f, 0.0f); transform.Translate(direction.normalized * mFollowSpeed * Time.deltaTime, Space.World); } else { combo = true; } if (comboTimer > 0.15 && combo) { attacking = true; flying = false; UpdateAnimator(); GameObject kB = Instantiate(kiBlast, transform.position, Quaternion.identity) as GameObject; KiBlast blast = kB.GetComponent <KiBlast>(); blastDir.x -= 0.3f; blast.setDirection(blastDir.normalized); comboTimer = 0; } } else if (engaging) { if (distance > 8 && distance < 14) { follow(); } else if (combo && comboTimer > 0.4) { flying = false; attack(); cAttacks++; comboTimer = 0; if (cAttacks > 2) { cAttacks = 0; combo = false; flyDir = (flyDir + 1) % 4; } } else if (flyDir == 0) { if (transform.position.y - mTarget.position.y > 5) { combo = true; } else { transform.Translate(Vector3.up * mFollowSpeed * Time.deltaTime, Space.World); } } else if (flyDir == 1) { if (transform.position.y - mTarget.position.y < 2.5) { combo = true; } else { Vector3 direction = new Vector3(-2.0f, -1.0f, 0.0f); transform.Translate(direction.normalized * mFollowSpeed * Time.deltaTime, Space.World); } } else if (flyDir == 2) { if (transform.position.y - mTarget.position.y > 5) { combo = true; } else { transform.Translate(Vector3.up * mFollowSpeed * Time.deltaTime, Space.World); } } else { if (transform.position.y - mTarget.position.y < 2.5) { combo = true; } else { Vector3 direction = new Vector3(2.0f, -1.0f, 0.0f); transform.Translate(direction.normalized * mFollowSpeed * Time.deltaTime, Space.World); } } if (distance > 7.0) { engaging = false; } } } }
public void KiBlastAttack(KiBlast kiBlast) { kiBlast.spriteSize = new Vector2(16, 16); kiBlast.velocity = new Vector2(kiBlast.trajectory.X, kiBlast.trajectory.Y); kiBlast.mySprite = new UniversalSprite(game, bossSpriteSheet, new Rectangle(125, 11, 8, 16), Color.White, SpriteEffects.None, new Vector2(1, 1), fireballLimiter, linkLayerDepth); }