} //FixedUpdate void patrol() { if (Mathf.Abs(transform.position.x - targetPos.x) > 0.25f && goLeft) { targetPos = new Vector2(playerPivotPos.x - 10f, yPos); anim.SetBool("walk", true); } else if (Mathf.Abs(transform.position.x - targetPos.x) > 0.25f && !goLeft) { targetPos = new Vector2(playerPivotPos.x + 10f, 0f); anim.SetBool("walk", true); } else if (Mathf.Abs(transform.position.x - targetPos.x) <= 0.25f) { anim.SetBool("walk", false); if (goLeft) { goLeft = false; } else if (!goLeft) { goLeft = true; } Invoke("walk", 2f); } rdb.position += seek.seekAndArrive(targetPos) * Time.deltaTime; } //patrol
void FixedUpdate() { targetLocation.y = rdb2.position.y; rdb2.position += seek.seekAndArrive(targetLocation) * Time.deltaTime; if (Time.time > nextFire && Vector2.Distance(helliTransform.position, targetLocation) > 1f) { nextFire = Time.time + fireRate; Instantiate(helliMissile, spawnpoint1.position, Quaternion.identity); } if (Vector2.Distance(helliTransform.position, targetLocation) < 0.25f) { elapsedTime += Time.deltaTime; if (elapsedTime > goRate) { if (faceRight) { goLeft = true; targetLocation = waypoint1.position; ChangeDirection(); } else { goLeft = false; targetLocation = waypoint2.position; ChangeDirection(); } elapsedTime = 0f; } } }
void FixedUpdate() { targetLocation.y = rdb2.position.y; rdb2.position += seek.seekAndArrive(targetLocation) * Time.deltaTime; if (Vector2.Distance(transform.position, targetLocation) < 0.25) { ChangeDirection(); elapsedTime += Time.deltaTime; if (elapsedTime > goRate) { if (faceRight) { goLeft = true; targetLocation = waypoint2.position; levelManager.objects.Add(Instantiate(guard1, new Vector2(waypoint1.position.x, waypoint1.position.y), Quaternion.identity) as GameObject); } else { goLeft = false; targetLocation = waypoint1.position; levelManager.objects.Add(Instantiate(guard1, new Vector2(waypoint2.position.x, waypoint2.position.y), Quaternion.identity) as GameObject); } elapsedTime = 0f; } } }
void Update() { if (!playerHealth.isDead) { if (sawTransform.rotation == targetRotation) { sawHead.enabled = true; } sawTransform.rotation = Quaternion.Slerp(sawTransform.localRotation, targetRotation, Time.deltaTime * 2f); targetPos.y = rdb2.position.y; rdb2.position += seek.seekAndArrive(targetPos) * Time.deltaTime; } else { Physics2D.IgnoreLayerCollision(9, 18, true); } }
void FixedUpdate() { if (playerTransform != null) { dogTransform.position = new Vector2(dogTransform.position.x, yPos); if (Mathf.Abs(dogTransform.position.x - targetLocation.x) > 0.25f && goLeft) { targetLocation = new Vector2(playerTransform.position.x - 3f, yPos); anim.SetBool("run", true); } if (Mathf.Abs(dogTransform.position.x - targetLocation.x) > 0.25f && !goLeft) { targetLocation = new Vector2(playerTransform.position.x + 3f, dogTransform.position.y); anim.SetBool("run", true); } if (Mathf.Abs(dogTransform.position.x - targetLocation.x) <= 0.25f) { anim.SetBool("run", false); if (dogTransform.position.x < playerTransform.position.x) { goLeft = false; } else { goLeft = true; } elapsedTime += Time.deltaTime; if (elapsedTime > runRate && !playerHealth.isDead) { run(); elapsedTime = 0f; } } rdb2.position += seek.seekAndArrive(targetLocation) * Time.deltaTime; } }
} //Update void FixedUpdate() { if (!playerHealth.isDead) { //check if on the ground ground = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer); if (ground) { targetPos.y = rdb.position.y; } else { anim.SetLayerWeight(0, 1f); } anim.SetLayerWeight(0, 1f); anim.SetLayerWeight(1, 0f); anim.SetBool("walk", false); if (anim.GetCurrentAnimatorStateInfo(1).IsTag("duck_shoot") && ground) { guardCollider.offset = new Vector2(0f, -1.96f); guardCollider.size = new Vector2(1.41f, 0.75f); } else { guardCollider.offset = new Vector2(0f, -0.29f); guardCollider.size = new Vector2(1.41f, 4.48f); } bool hitLeft = Physics2D.Raycast(new Vector2(transform.position.x - 1f, transform.position.y), Vector2.left, 9f, playerMask); bool hitRight = Physics2D.Raycast(new Vector2(transform.position.x + 1f, transform.position.y), Vector2.right, 9f, playerMask); if ((!hitLeft && !hitRight) && ground) { rdb.position += seek.seekAndArrive(targetPos) * Time.deltaTime; anim.SetLayerWeight(0, 1f); anim.SetBool("walk", true); shoot.enabled = false; count = 0; } else if ((hitRight && !faceRight) && ground) { goLeft = false; anim.SetLayerWeight(1, 1f); ChangeDirection(); shoot.enabled = true; } else if ((hitRight && faceRight) && ground) { anim.SetLayerWeight(1, 1f); shoot.enabled = true; } else if (hitLeft && faceRight) { goLeft = true; anim.SetLayerWeight(1, 1f); ChangeDirection(); shoot.enabled = true; } else if (hitLeft && !faceRight) { anim.SetLayerWeight(1, 1f); shoot.enabled = true; } if (Mathf.Abs(transform.position.x - targetPos.x) <= 0.25f) { anim.SetBool("walk", false); if (transform.position.x > player.position.x) { goLeft = true; faceRight = true; ChangeDirection(); } } } else { anim.SetLayerWeight(1, 0f); anim.SetLayerWeight(0, 1f); anim.SetBool("walk", false); shoot.enabled = false; } }
} //initialize void Girl2Movement() { if (doNext == action.JUMP_RIGHT) { if (parm <= 1f) { rotateAntiClockwise(); } //if else { doNext = action.DO_NOTHING; anim.SetTrigger("idle"); girlTransform.position = new Vector3(girlTransform.position.x, girlTransform.position.y, 0.45f); parm = 0f; angle = 0f; currentPos += 1; } //else } //if if (doNext == action.JUMP_LEFT) { if (parm <= 1f) { rotateClockWise(); } //if else { doNext = action.DO_NOTHING; anim.SetTrigger("idle"); girlTransform.position = new Vector3(girlTransform.position.x, girlTransform.position.y, 0.45f); parm = 0f; angle = 0f; currentPos -= 1; } //if else } //if if (doNext == action.RUN_RIGHT) { if (Mathf.Abs(girlTransform.position.x - targetPos.x) >= 0.5f) { anim.SetTrigger("run"); girlRigidBody.position += seek.seekAndArrive(targetPos) * Time.deltaTime; } else { anim.SetTrigger("idle"); girlTransform.position = new Vector3(girlTransform.position.x, girlTransform.position.y, 0.45f); doNext = action.DO_NOTHING; currentPos += 1; } //if else } //if if (doNext == action.RUN_LEFT) { if (Mathf.Abs(girlTransform.position.x - targetPos.x) >= 0.5f) { anim.SetTrigger("run"); girlRigidBody.position += seek.seekAndArrive(targetPos) * Time.deltaTime; } else { anim.SetTrigger("idle"); girlTransform.position = new Vector3(girlTransform.position.x, girlTransform.position.y, 0.45f); doNext = action.DO_NOTHING; currentPos -= 1; } // if else } //if } //Girl2Movement
void Clown2Movement() { if (doNext == action.JUMP_RIGHT) { if (parm <= 1f) { Vector2 point = calculateBezierPoint(pathPoints[currentPos].position, controlPoints[nextPoint.leftPoint].position, controlPoints[nextPoint.rightPoint].position, pathPoints[currentPos + 1].position, parm); girlTransform.position = point; if (angle <= 1080f) { anim.SetTrigger("jump"); girlTransform.rotation = Quaternion.Euler(0f, 180f, angle); } angle += 30f; parm += 0.025f; } //if else { doNext = action.DO_NOTHING; anim.SetTrigger("idle"); girlTransform.position = new Vector3(girlTransform.position.x, girlTransform.position.y, 0.45f); parm = 0f; angle = 0f; currentPos += 1; } //else } //if if (doNext == action.JUMP_LEFT) { if (parm <= 1f) { Vector2 point = calculateBezierPoint(pathPoints[currentPos].position, controlPoints[nextPoint.rightPoint].position, controlPoints[nextPoint.leftPoint].position, pathPoints[currentPos - 1].position, parm); girlTransform.position = point; if (angle <= 1080f) { anim.SetTrigger("jump"); girlTransform.rotation = Quaternion.Euler(0f, 0f, angle); }//if angle -= 30f; parm += 0.025f; } //if else { doNext = action.DO_NOTHING; anim.SetTrigger("idle"); girlTransform.position = new Vector3(girlTransform.position.x, girlTransform.position.y, 0.45f); parm = 0f; angle = 0f; currentPos -= 1; } //if else } //if if (doNext == action.RUN_RIGHT) { Vector2 targetPos = pathPoints[4].position; if (Mathf.Abs(girlTransform.position.x - targetPos.x) >= 0.5f) { anim.SetTrigger("run"); girlRigidBody.position += seek.seekAndArrive(targetPos) * Time.deltaTime; } else { anim.SetTrigger("idle"); girlTransform.position = new Vector3(girlTransform.position.x, girlTransform.position.y, 0.45f); doNext = action.DO_NOTHING; currentPos += 1; } //if else } //if if (doNext == action.RUN_LEFT) { Vector2 targetPos = pathPoints[3].position; if (Mathf.Abs(girlTransform.position.x - targetPos.x) >= 0.5f) { anim.SetTrigger("run"); girlRigidBody.position += seek.seekAndArrive(targetPos) * Time.deltaTime; } else { anim.SetTrigger("idle"); girlTransform.position = new Vector3(girlTransform.position.x, girlTransform.position.y, 0.45f); doNext = action.DO_NOTHING; currentPos -= 1; } // if else } //if } //Clown2Movement