public override void OnInitializeEntity() { if (initialDirection != 1 && initialDirection != -1 || randomiseInitialDirection) { int r = UnityEngine.Random.Range(0, 2); if (r == 0) { currentDirection = 1; } else { currentDirection = -1; } } else { currentDirection = initialDirection; } eTransform.parent = parentMap.transform; eTransform.localPosition = BlockUtilities.GetMathematicalPosition(parentMap, x, y, z); ProcessPatrolNode(); }
void OnDrawGizmos() { BlockMap map = parentMap; List <Vector3> v = currentPath; Gizmos.color = new Color(0.0f, 0.0f, 1.0f, 0.5f); for (int i = 0; i < v.Count; i++) { Vector3 pos = BlockUtilities.GetMathematicalPosition(map, (int)v[i].x, (int)v[i].y, (int)v[i].z); pos = map.transform.TransformPoint(pos); Gizmos.DrawSphere(pos, 0.5f); } }
void AddPlayerToMap() { player_x = start_player_x; player_y = start_player_y; streamingMap.DrawMap(player_x, player_y, 1, drawRadius, true); //We want to draw the map before we add the player player = GameObject.Instantiate(playerPrefab) as PlatformerPlayer; Vector3 coords = BlockUtilities.GetMathematicalPosition(streamingMap.blockMap, player_x, player_y, 0); player.transform.parent = streamingMap.blockMap.transform; player.transform.localPosition = coords; player.InitializeEntity(streamingMap.blockMap); }
void OnDrawGizmos() { BlockMap map = GameObject.FindObjectOfType(typeof(BlockMap)) as BlockMap; foreach (string s in reservationRegister.Keys) { List <Vector3> v = new List <Vector3>(reservationRegister[s]); Gizmos.color = new Color(0.0f, 1.0f, 0.0f, 0.5f); for (int i = 0; i < v.Count; i++) { Vector3 pos = BlockUtilities.GetMathematicalPosition(map, (int)v[i].x, (int)v[i].y, (int)v[i].z); pos = map.transform.TransformPoint(pos); Gizmos.DrawSphere(pos, 0.5f); } } }
public void ProcessPatrolNode() { sourcePosition = eTransform.localPosition; if (IsStuck()) { OnCannotMove(x, y, z); return; } if (patrolAxis == PatrolAxis.Horizontal) { targetCoords = new Vector3(x + currentDirection, y, z); targetPosition = BlockUtilities.GetMathematicalPosition(parentMap, x + currentDirection, y, z); } else if (patrolAxis == PatrolAxis.Vertical) { targetCoords = new Vector3(x, y + currentDirection, z); targetPosition = BlockUtilities.GetMathematicalPosition(parentMap, x, y + currentDirection, z); } if (!CanMoveTo((int)targetCoords.x, (int)targetCoords.y, (int)targetCoords.z)) { ReachEndOfPatrol(x, y, z); return; } controller.ReserveBlock(entityType, targetCoords); //Now decide where we're facing int x_dir = x - (int)targetCoords.x; int y_dir = (int)targetCoords.y - y; if (x_dir > 0) { eTransform.up = upDirection; eTransform.forward = rightDirection; } else if (x_dir < 0) { eTransform.up = upDirection; eTransform.forward = leftDirection; } else if (y_dir > 0) { if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward) { eTransform.forward = frontDirection; } else { eTransform.forward = downDirection; Vector3 rot = eTransform.localRotation.eulerAngles; rot.y = 0.0f; eTransform.localRotation = Quaternion.Euler(rot); } } else if (y_dir < 0) { if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward) { eTransform.forward = backDirection; } else { eTransform.forward = upDirection; } } SetIsMoving(true); }
public void ProcessPathing() { //Debug.Log(name + " Processing pathing at: " + x + "," + y + "," + z); if (currentPath.Count <= 0) { //Debug.Log ("End path"); OnReachPathEnd(x, y, z); return; } if (currentPath.Count > 0) { Vector3 targetNode = currentPath[0]; currentPath.RemoveAt(0); if (!CanWalkTo((int)targetNode.x, (int)targetNode.y, z)) { currentPath.Clear(); Idle(); return; } targetCoords = new Vector3(targetNode.x, targetNode.y, z); targetPosition = BlockUtilities.GetMathematicalPosition(parentMap, (int)targetNode.x, (int)targetNode.y, z); controller.ReserveBlock(entityType, targetCoords); startPosition = eTransform.localPosition; //Debug.Log(name + " Moving to: " + targetCoords.ToString()); currentLerpAmount = 0.0f; isMoving = true; //Now decide where we're facing int x_dir = x - (int)targetCoords.x; int y_dir = (int)targetCoords.y - y; if (x_dir > 0) { eTransform.up = upDirection; eTransform.forward = rightDirection; } else if (x_dir < 0) { eTransform.up = upDirection; eTransform.forward = leftDirection; } else if (y_dir > 0) { if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward) { eTransform.forward = frontDirection; } else { eTransform.forward = downDirection; Vector3 rot = eTransform.localRotation.eulerAngles; rot.y = 0.0f; eTransform.localRotation = Quaternion.Euler(rot); } } else if (y_dir < 0) { if (parentMap.growthAxis == BlockMap.GrowthAxis.Forward) { eTransform.forward = backDirection; } else { eTransform.forward = upDirection; } } } else { Idle(); } }
void InitializePosition() { eTransform.localPosition = BlockUtilities.GetMathematicalPosition(parentMap, x, y, z); }
public override void OnBlockEntry(int x, int y, int z) { hasActedForBlock = false; currentTilePosition = BlockUtilities.GetMathematicalPosition(parentMap, x, y, z); }