IEnumerator MovingToPlayer() { bool hasLoS = true; Vector2 dirToPlayer; Vector2 lastPlayerPos = playerPos.position; int layerMask = 1 << 11; layerMask = ~layerMask; while (hasLoS) { dirToPlayer = (playerPos.position - transform.position).normalized; RaycastHit2D hit = Physics2D.Raycast(transform.position, playerPos.position - transform.position, 20f, layerMask); if (hit && hit.collider.CompareTag("Player")) { C_movement.push(dirToPlayer * Movement.enemyAcc); lastPlayerPos = playerPos.position; } else { C_enemy.setLastPlayerPos(lastPlayerPos); sm.toState("Seeking"); hasLoS = false; } yield return(new WaitForSeconds(0.25f)); } }
void FixedUpdate() { if (target == null) { if (!searchingForPlayer) { searchingForPlayer = true; StartCoroutine(SearchForPlayer()); } return; } //TODO: Always look at player? if (path == null) { return; } //Checks if the enemy has finished it's path if (currentWaypoint >= path.vectorPath.Count) { if (pathIsEnded) { return; } //Debug.Log ("End of path reached."); pathIsEnded = true; return; } pathIsEnded = false; //Directon to the next waypoint Vector3 dir = (path.vectorPath[currentWaypoint] - transform.position).normalized; dir *= Movement.enemyAcc; //Debug.Log(dir); //Move the AI C_movement.push(new Vector2(dir.x, dir.y)); //rb.AddForce(dir, fMode); float dist = Vector3.Distance(transform.position, path.vectorPath [currentWaypoint]); if (dist < nextWaypointDistance) { currentWaypoint++; return; } }
IEnumerator dash() { Debug.Log("starting Dash corotine"); for (float u = 0; u < .3; u += Time.deltaTime) { Debug.Log(u); checkCollisions(); //C_movement.push(direction * 100); //C_movement.clampSpeed(); if (newCollision()) //if there is a new collision (if the player hits an enemy), slash { yield return(new WaitForFixedUpdate()); //Time.timeScale = .1f; //Time.fixedDeltaTime = .1f * 0.02f; SendMessage("createSlashAttack"); for (float y = 0; y < .05; y += Time.deltaTime) { //C_movement.push(direction * 100); checkCollisions(); checkForWall(); yield return(new WaitForFixedUpdate()); u += Time.deltaTime; } //Time.timeScale = 1f; //Time.fixedDeltaTime = 1f * 0.02f; C_movement.push(direction * 100); //C_movement.clampSpeed(); } yield return(new WaitForFixedUpdate()); checkForWall(); //exits if the player hits a wall } sm.toState("Default"); }
//sub functions //movement options void movementInputs() //move using wasd { C_movement.push(Movement.wasd() * moveSpeed); }