public GhostController ClosestGhostToCharacter(CharacterMotor character) { Vector3 characterPos = character.transform.position; characterPos.y = 0f; GhostController closest = null; float sqrDistToClosest = Mathf.Infinity; foreach (CharacterMotor currNeighbor in _characters) { if (currNeighbor == character) { continue; } Vector3 currNeighborPos = currNeighbor.transform.position; currNeighborPos.y = 0f; float sqrDistToCurrNeighbor = (currNeighborPos - characterPos).sqrMagnitude; if (closest == null || sqrDistToCurrNeighbor < sqrDistToClosest) { sqrDistToClosest = sqrDistToCurrNeighbor; GhostController currNeighborGhostController = currNeighbor.GetComponent <GhostController>(); if (currNeighborGhostController != null) { closest = currNeighborGhostController.GetComponent <GhostController>(); } } } return(closest); }
public void StartPossessionInRoomForGhost(Room room, GhostController ghost) { if (CanPossess && !_catchingInProgress) { CharacterMotor character = ghost.GetComponent <CharacterMotor>(); GhostController closest = room.ClosestGhostToCharacter(character); if (closest == null) { Events.g.Raise(new PossessionEvent(false, room: null)); return; } Events.g.Raise(new PossessionEvent(true, room: room)); closest.enabled = true; ghost.enabled = false; _possessionCount++; _possessionChargeTimer.Stop(); _possessionChargeTimer.Reset(); _possessionForcedTimer.Stop(); _possessionForcedTimer.Reset(); StartPossessionCharge(); } else { Events.g.Raise(new PossessionEvent(false, room: null)); } }
public void Enter() { //Debug.Log("entering the searching state"); agent = owner.GetComponent <NavMeshAgent>(); //move to last seen position of the player agent.destination = owner.lastSeenPosition; agent.isStopped = false; }
public void Enter() { //when we enter the patrol state, we want to find the next waypoint and start moving towards it //Debug.Log("entering patrol state"); waypoint = owner.waypoint; agent = owner.GetComponent <NavMeshAgent>(); agent.destination = waypoint.transform.position; //start moving, in case we were previously stopped agent.isStopped = false; }
public void Enter() { //if they are entering the attack state, find the last seen location and start moving if stopped //Debug.Log("entering attack state"); agent = owner.GetComponent <NavMeshAgent>(); if (owner.seenTarget) { agent.destination = owner.lastSeenPosition; agent.isStopped = false; } }
void Rewind() { if (GameManager.instance.positionsBuffer.Count > 3) { transform.position = GameManager.instance.positionsBuffer[0]; GameManager.instance.positionsBuffer.RemoveAt(2); GameManager.instance.positionsBuffer.RemoveAt(1); GameManager.instance.positionsBuffer.RemoveAt(0); } else { GameManager.instance.positionsBuffer.Reverse(); transform.position = GameManager.instance.positionsBuffer[0]; GameManager.instance.positionsBuffer.Clear(); ghost.GetComponent <Materialize>().active = false; ghost.GetComponent <Materialize>().value = 0.3f; ghost.GetComponent <MeshRenderer>().enabled = false; link.gameObject.SetActive(false); coll.isTrigger = false; rb.gravityScale = 1.0f; rewinding = false; rewindParticles.Stop(); } }