public virtual void Initialize (MazeCell cell, MazeDirection direction = MazeDirection.North) { this.cell = cell; this.direction = direction; transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
private void CreateWall(MazeCell cell, MazeCell otherCell, MazeDirection direction) { MazeWall wall = Instantiate(wallPrefabs [Random.Range(0, wallPrefabs.Length)]) as MazeWall; wall.Initialize(cell, otherCell, direction); GameObject newColumn = Instantiate(columnPrefab) as GameObject; newColumn.transform.parent = cell.transform; newColumn.transform.localPosition = Vector3.zero; newColumn.transform.localRotation = direction.ToRotation(); if (cell.altitude > 0) { newColumn.transform.localPosition = new Vector3( newColumn.transform.localPosition.x, //-cell.transform.localPosition.y, -cell.altitude * 1.078f, newColumn.transform.localPosition.z); wall.transform.localPosition = new Vector3( wall.transform.localPosition.x, //-cell.transform.localPosition.y, -cell.altitude * 1.078f, wall.transform.localPosition.z); MazeWall railing = Instantiate( railingPrefabs [Random.Range(0, railingPrefabs.Length)]) as MazeWall; railing.Initialize(cell, otherCell, direction); } }
public void Initialize(MazeCell cell, MazeDirection direction) { this.cell = cell; this.direction = direction; transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
public void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection direction) { this.direction = direction; this.gameObject.name = "Wall of " + cell.ToString() + " " + direction.ToString(); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
public void UpdateTurning() { float _margin = 0.5f; // if the rotation is this close to the desired rotation, the turn is complete. Expressed in degrees if (transform.localRotation.eulerAngles.y > (currentDirection.ToRotation().eulerAngles.y - _margin) && transform.localRotation.eulerAngles.y < (currentDirection.ToRotation().eulerAngles.y + _margin)) // check if current rotation is very close to desired rotation { // Debug.Log("Turn Complete!"); transform.localRotation = currentDirection.ToRotation(); // set localRotation to EXACTLY the rotation we want to ensure accuracy isTurning = false; } else { transform.localRotation = Quaternion.Lerp(transform.localRotation, currentDirection.ToRotation(), Time.deltaTime * turnSpeed); mustTurnLeft = false; mustTurnRight = false; } }
private void Look(MazeDirection direction) { transform.localRotation = direction.ToRotation(); currentDirection = direction; //set mousePosLast to current mouseposition on every change -> avoids strange effects mousePosLast = Input.mousePosition.x; }
void CreateWall(MazeCell cell, MazeCell otherCell, MazeDirection direction) { GameObject wall = Instantiate(wallPrefab); wall.transform.parent = gameObject.transform; wall.transform.localPosition = cell.position; wall.transform.localRotation = direction.ToRotation(); }
public void Initialize (MazeCell cell, MazeCell otherCell, MazeDirection direction) { this.cell = cell; this.otherCell = otherCell; this.direction = direction; cell.SetEdge(direction, this); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
public virtual void Initialize(MazeCell cell, MazeDirection dir = (MazeDirection)1) { this.cell = cell; Vector3 tempLocalPosition = this.transform.localPosition; transform.parent = cell.transform; transform.localPosition = tempLocalPosition; this.transform.rotation = dir.ToRotation() * this.transform.rotation; }
public void Initialize(MazeCell cell, MazeCell neighbour, MazeDirection direction) { this.cell = cell; this.neighbour = neighbour; this.direction = direction; cell.SetEdge(direction, this); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
public virtual void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection direction) { this.cell = cell; this.otherCell = otherCell; this.direction = direction; cell.SetEdge(direction, this); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
public void Initialize(MazeCell cell1, MazeCell cell2, MazeDirection direc) { this.cell = cell1; this.otherCell = cell2; this.direc = direc; cell1.SetEdge(direc, this); transform.parent = cell1.transform; transform.localPosition = Vector3.zero; transform.localRotation = direc.ToRotation(); }
public void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection dir) { this.cell = cell; this.otherCell = otherCell; this.direction = dir; cell.SetEdge(dir, this); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = dir.ToRotation(); transform.localScale = new Vector3(1f, 1f, 1f); }
public virtual void Initialize(MazeCell parentCell, MazeCell neighbourCell, MazeDirection direction) { this.parentCell = parentCell; this.neighbourCell = neighbourCell; this.direction = direction; parentCell.SetEdge(direction, this); transform.parent = parentCell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
public virtual void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection direction) { this.cell = cell; this.otherCell = otherCell; this.direction = direction; cell.SetEdge(direction, this); transform.parent = cell.transform; transform.localPosition = Vector3.zero; //rotating the cell edge in right direction instead of only north side transform.localRotation = direction.ToRotation(); }
public MazeDirection direction; // A direction to remember the cells orientation //================================================================================= // Function to make the edges children of their cells and place them in the same // location. //================================================================================= public void Initialise(MazeCell cell, MazeCell otherCell, MazeDirection direction) { this.cell = cell; this.otherCell = otherCell; this.direction = direction; cell.SetEdge(direction, this); transform.parent = cell.transform; transform.localPosition = Vector3.zero; // Accesses ToRotation function in MazeDirections so walls spawn on side where the maze was interrupted by a previously activated cell transform.localRotation = direction.ToRotation(); }
public void InitializeCorner(GameObject prefab, MazeDirection dir, int delta) { GameObject dgo = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject; //dgo.transform.parent = transform; dgo.transform.SetParent(transform, false); dgo.transform.localPosition = Vector3.zero; dgo.transform.localRotation = dir.ToRotation(); dgo.transform.localScale = new Vector3(delta, dgo.transform.localScale.y, dgo.transform.localScale.z); initializedCorners[(int)((float)dir + 0.5f + (float)delta / 2.0f) % MazeDirections.Count] = true; }
public void Initialize(MazeCell _cell, MazeCell _otherCell, MazeDirection _direction, EdgeType _type) { cell = _cell; otherCell = _otherCell; direction = _direction; edgeType = _type; cell.SetEdge(direction, this); transform.name += direction.ToString(); transform.parent = _cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
//Initialise method to make the edges children of the cell and place them at the same coordinates public void Initialize(CS_MazeCell a_cell, CS_MazeCell a_otherCell, MazeDirection a_direction) { //Setting the definitions of the local variables to those that have been input into the function this.cell = a_cell; this.otherCell = a_otherCell; this.direction = a_direction; a_cell.SetEdge(a_direction, this); transform.parent = a_cell.transform; transform.localPosition = Vector3.zero; //This prevents all the walls from facing north and face their actual direction transform.localRotation = direction.ToRotation(); }
public void Init(MazeCell cell, MazeCell other, MazeDirection direction) { this.cell = cell; this.other = other; this.direction = direction; cell.SetEdge(this, direction); transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
public void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection direction) { this.cell = cell; this.otherCell = otherCell; this.direction = direction; float small = 0.001f; Vector3 scale = transform.localScale; cell.SetEdge(direction, this); transform.parent = cell.transform; transform.localPosition = new Vector3(Random.Range(-small, small), Random.Range(-small, small), Random.Range(-small, small)); transform.localRotation = direction.ToRotation(); transform.localScale = scale; }
//initialize a directional signpost pointing in direction dir and in a quadrant of the cell not //containing the player located at playerPosition. public void AddSignPost(MazeDirection dir, Vector3 playerPosition) { if (signpostInstance != null) { return; } signpostInstance = Instantiate(signpostPrefab) as DirectionalSignPost; signpostInstance.transform.parent = transform; Vector3 relativePos = playerPosition - transform.localPosition; signpostInstance.transform.localPosition = new Vector3( (relativePos.x <= 0 ? 0.25f : -0.25f), -1.5f, (relativePos.z <= 0 ? 0.25f : -0.25f) ); signpostInstance.transform.localRotation *= dir.ToRotation(); }
/// <summary> /// Make edges to cells of their cells and place them in the same place. /// </summary> /// <param name="cell">Current cell point.</param> /// <param name="otherCell">Neighbour cell point.</param> /// <param name="direction">Direction for continue the cell building.</param> public virtual void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection direction) { // Initializing. Cell = cell; OtherCell = otherCell; Direction = direction; // Informs the cell that an edge has been created. cell.SetEdge(direction, this); // Set as child. transform.parent = cell.transform; // Reset locals. transform.localPosition = Vector3.zero; // Turn walls in the right direction. transform.localRotation = direction.ToRotation(); }
public virtual void Initialize( MazeCell cell, MazeCell otherCell, MazeDirection direction) { this.cell = cell; this.otherCell = otherCell; this.direction = direction; cell.SetEdge(direction, this); if (null != otherCell) { if (cell == otherCell) { Debug.LogError("An edge has itself for a neighbor!"); } otherCell.SetEdge(direction.GetOpposite(), this); } transform.parent = cell.transform; transform.localPosition = Vector3.zero; transform.localRotation = direction.ToRotation(); }
private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction) { bool createDecor = Random.value < cell.room.settings.decorProbability ? true : false; if (otherCell.coordinates.x == playerCoordinates.x && otherCell.coordinates.z == playerCoordinates.z) { createDecor = false; } MazePassage prefab = Random.value < doorProbability ? doorPrefab[Random.Range(0, doorPrefab.Length)] : passagePrefab; MazePassage passage = Instantiate(prefab, cell.transform.position, direction.ToRotation()) as MazePassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(prefab) as MazePassage; if (passage is MazeDoor) { otherCell.Initialize(CreateRoom(cell.room.settingsIndex), false, useShaderMaterials); } else { otherCell.Initialize(cell.room, createDecor, useShaderMaterials); } passage.Initialize(otherCell, cell, direction.GetOpposite()); }
public virtual void Initialize(MazeCell cell, MazeDirection direction) { base.Initialize(cell); this.direction = direction; transform.localRotation = direction.ToRotation(); }
private void Look(MazeDirection direction) { transform.localRotation = direction.ToRotation(); currentDirection = direction; }
public void SetDirection(MazeDirection direction) { m_CurrentDirection = direction; transform.localRotation = direction.ToRotation(); }
void Rotate(MazeDirection direction) { transform.localRotation = direction.ToRotation(); currentDirection = direction; }
private void CreatePassage( List <MazeCell> activeCells, MazeCell cell, MazeCell otherCell, MazeDirection direction) { // Create one of the possible passable edges from one a cell in one // room to a cell in another. MazePassage prefab = passagePrefab; // generic passage if (cell.altitude == 0 && Random.value < doorProbability) { // Possibly make a door from one room to the next prefab = doorPrefab; if (Random.value < doorProbability && CanCreateStairs(cell, otherCell, direction)) { // Instead of a door, let's try to make stairs. Stiars occupy // both cell and other cell and enforce constraints on // a low landing cell at the base of the stairs and a // high landing cell at the top of the stairs. prefab = passagePrefab; // Not a door after all! cell.accessory = Instantiate(stairsPrefab) as MazeCellAccessory; cell.accessory.cell = cell; cell.accessory.transform.parent = cell.transform; cell.accessory.transform.localPosition = Vector3.zero; cell.accessory.transform.localRotation = direction.ToRotation(); otherCell.Initialize(cell.GetRoomNumber()); IntVector2 highLandingCoordinates = otherCell.coordinates + direction.ToIntVector2(); MazeCell highLandingCell = CreateCell( highLandingCoordinates, 1, cellPrefab); activeCells.Add(highLandingCell); highLandingCell.Initialize(otherCell.GetRoomNumber() + 1); MazePassage landingPassage = Instantiate(prefab) as MazePassage; landingPassage.Initialize(otherCell, highLandingCell, direction); GameObject newColumn = Instantiate(columnPrefab) as GameObject; newColumn.transform.parent = otherCell.transform; newColumn.transform.localPosition = Vector3.zero; newColumn.transform.localRotation = direction.ToRotation(); if (null != railingColumnPrefab) { GameObject newRailingColumn = Instantiate(railingColumnPrefab) as GameObject; newRailingColumn.transform.parent = highLandingCell.transform; newRailingColumn.transform.localPosition = Vector3.zero; newRailingColumn.transform.localRotation = direction.ToRotation(); } } else { // Doors alsways change room numbers otherCell.Initialize(cell.GetRoomNumber() + 1); } } else { // This passage is neither door nor stair otherCell.Initialize(cell.GetRoomNumber()); otherCell.altitude = cell.altitude; otherCell.transform.localPosition = new Vector3(otherCell.transform.localPosition.x, otherCell.transform.localPosition.y + otherCell.altitude * 1.078f, otherCell.transform.localPosition.z); } MazePassage passage = Instantiate(prefab) as MazePassage; passage.Initialize(cell, otherCell, direction); }
void FixedUpdate() { if (1 < route.Count) { // Player has not yet completed route. There is at least one more cell // to visit in the route. float deltaToNextCell = Mathf.Max( Mathf.Abs(targetPosition.x - transform.position.x), Mathf.Abs(targetPosition.z - transform.position.z)); if (0.4f > deltaToNextCell) { // The player is close to the immediate destination so go ahead and process // the transition from the current cell to the next cell. if (GetCurrentCell() != null) { GetCurrentCell().OnPlayerExited(); } route.RemoveAt(0); GetCurrentCell().OnPlayerEntered(); targetPosition = GetCurrentCell().transform.position; // Debug.LogWarning (string.Format( // "Move To:{0} {1}", // GetCurrentCell().name, targetPosition.y)); } } float delta = Mathf.Max(Mathf.Abs(targetPosition.x - transform.position.x), Mathf.Abs(targetPosition.z - transform.position.z)); if (delta > smallDelta) { // Calculate direction of travel Vector3 directionToTargetPosition = targetPosition - transform.position; // Face direction of travel Quaternion targetRotation = Quaternion.LookRotation( directionToTargetPosition, Vector3.up); Quaternion newRotation = Quaternion.Lerp(player_rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime); player_rigidbody.MoveRotation(newRotation); if (2 < route.Count) // The planned destination is far so run there { const string message = "Run"; actions.SendMessage(message, SendMessageOptions.DontRequireReceiver); isRunning = true; } else // The planned destination is very near so slow down { if (1 == route.Count && delta > 0.2f) { const string message = "Walk"; actions.SendMessage(message, SendMessageOptions.DontRequireReceiver); isRunning = false; } } if (isRunning) { player_rigidbody.MovePosition(transform.position + transform.forward * Time.deltaTime * runSpeedMultiplier); } else { player_rigidbody.MovePosition( transform.position + transform.forward * Time.deltaTime); } } else { const string message = "Stay"; actions.SendMessage(message, SendMessageOptions.DontRequireReceiver); float angle = Quaternion.Angle(transform.rotation, lookDirection.ToRotation()); if (Mathf.Abs(angle) > mediumDelta) { Rigidbody player_rigidbody = GetComponent <Rigidbody> (); Quaternion newRotation = Quaternion.Lerp(player_rigidbody.rotation, lookDirection.ToRotation(), turnSmoothing * Time.deltaTime); player_rigidbody.MoveRotation(newRotation); } } }