void StartActionAttempt(Vector2 direction) { Vector2 newTile = new Vector2(transform.position.x + direction.x, transform.position.z + direction.y); Vector2 posV2 = TerrainManager.PosToV2(transform.position); Quaternion targetRot = Quaternion.Euler(new Vector3(0f, Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg, 0f)); // test to see if body is standing on tile bool canAttack = (tm.GetTileAtPosition(TerrainManager.PosToV2(transform.position)) && body.attacksLeft > 0); bool wantsToAttack = (isPlayer) ? tm.EnemyInRange(posV2, direction, body.weapon.info.range) : tm.PlayerInRange(posV2, direction, body.weapon.info.range); if (wantsToAttack && canAttack) { body.AttackInDir(targetRot, direction); return; } else if (wantsToAttack) { bool canMove = (isPlayer) ? tm.EnemyInRange(posV2, direction, 1) : tm.PlayerInRange(posV2, direction, 1); if (canMove) { EmptyAction(); return; } } Vector3 targetPos = new Vector3(transform.position.x + direction.x, 0f, transform.position.z + direction.y); if (!tm.GetTileAtPosition(newTile)) { tm.CreateBus(targetPos); // update location if (body.location != null) { body.location.PlayerExitIsland(); body.location = null; } } else { float newTileHeight = tm.GetTileAtPosition(newTile).transform.position.y; GameObject building = tm.GetBuildingAtPosition(newTile); if (building != null) { Building buildingScript = building.GetComponent <Building> (); if (buildingScript.state != Building.BuildingState.Blueprint) { newTileHeight += buildingScript.height; } } targetPos += new Vector3(0f, newTileHeight, 0f); // update location body.location = tm.tiles [newTile].island; if (isPlayer) { body.location.PlayerEnterIsland(); } } body.MoveToPos(targetPos, targetRot); }