public void removeSpatialLine(SpatialLine sl) { foreach (SpatialLine _sl in _spatialLines) { if (_sl.begin == sl.begin && _sl.end && sl.end) { _spatialLines.Remove(_sl); break; } } if (GameManager.instance.player.currentSpatialLine == sl) { GameManager.instance.player.chooseNearestSpatialLine(); } }
private void ReachEnd() { isMoving = false; if (addSpatialLine) { spatialRoom.addSpatialLine(addedSpatialLine); } if (removeSpatialLine) { nextSpatialRoom.removeSpatialLine(removedSpatialLine); SpatialRoom save = spatialRoom; spatialRoom = nextSpatialRoom; nextSpatialRoom = save; SpatialLine slSave = addedSpatialLine; addedSpatialLine = removedSpatialLine; removedSpatialLine = slSave; } if (scriptTwoSteps) { startPos = endPos.position; endPos.position = endPosStep2.position; lampAnimator.enabled = false; lamp.enabled = true; isActivated = false; enterCol.enabled = false; isStarted = false; AkSoundEngine.PostEvent(breakSound, gameObject); //StartCoroutine(StopEngineCoroutine()); if (blinkingLight != null) { lampAnimator.enabled = false; lamp.enabled = true; blinkingLight.enabled = true; } scriptTwoSteps = false; } else if (isStarted && isBidirectional) { Vector3 save = startPos; startPos = endPos.position; endPos.position = save; isActivated = false; direction *= -1; } }
public void addSpatialLine(SpatialLine sl) { bool inserted = false; foreach (SpatialLine _sl in _spatialLines) { if (sl.begin.position.z < _sl.begin.position.z) { _spatialLines.Insert(spatialLines.IndexOf(_sl), sl); inserted = true; break; } } if (!inserted) { _spatialLines.Add(sl); } }
public void chooseNearestSpatialLine() { float zOffset = Mathf.Infinity; foreach (SpatialLine sl in currentSpatialRoom._spatialLines) { if (sl.begin.position.x <= transform.position.x && sl.end.position.x >= transform.position.x) { float offset = Mathf.Abs(sl.begin.position.z - transform.position.z); if (offset < zOffset) { zOffset = offset; currentSpatialLine = sl; isChangingSpatialLine = true; changingLineDirection = (sl.begin.position.z - transform.position.z) > 0 ? 1 : -1; } } } //print(currentSpatialLine.begin.position + " - " + currentSpatialLine.end.position); }
private void Move() { isMoving = false; lMovement = Vector3.zero; Vector3 camMove = Vector3.zero; if (hMove < deadZoneValue && hMove > -deadZoneValue && inputMode == InputMode.Pad) { hMove = 0; } if (!needsCentering) { if (Mathf.Abs(hMove) > 0) { lMovement += HorizontalMove(hMove); } else if (_horizontalAccDecLerpValue != 0) { lMovement += HorizontalSlowDown(); } } if (currentSpatialSas == null) { if ((vMove >= changeLineDeadZoneValue || (vMove > 0 && inputMode == InputMode.PC)) && !(isChangingSpatialLine && changingLineDirection == 1)) { for (int i = 0; i < currentSpatialRoom._spatialLines.Count; i++) { SpatialLine sl = currentSpatialRoom._spatialLines[i]; if (sl.begin.position.z > currentSpatialLine.begin.position.z) { if (transform.position.x >= sl.begin.position.x && transform.position.x <= sl.end.position.x) { currentSpatialLine = sl; isChangingSpatialLine = true; changingLineDirection = 1; break; } } } } else if ((vMove <= -changeLineDeadZoneValue || (vMove < 0 && inputMode == InputMode.PC)) && !(isChangingSpatialLine && changingLineDirection == -1)) { for (int i = currentSpatialRoom._spatialLines.Count - 1; i >= 0; i--) { SpatialLine sl = currentSpatialRoom._spatialLines[i]; if (sl.begin.position.z < currentSpatialLine.begin.position.z) { if (transform.position.x >= sl.begin.position.x && transform.position.x <= sl.end.position.x) { currentSpatialLine = sl; isChangingSpatialLine = true; changingLineDirection = -1; break; } } } } } if (lMovement != Vector3.zero || isChangingSpatialLine) { isMoving = true; if (GameManager.instance.controls.GetAxisRaw("Sprint") != 0)// && inverse==1) { isRunning = true; animator.SetBool("IsRunning", true); moveSpeed = runSpeed; } else { isRunning = false; animator.SetBool("IsRunning", false); moveSpeed = walkSpeed; } if (needsCentering && currentSpatialLine.begin.position.z > transform.position.z) { float targetPosX = (currentSpatialLine.end.position.x + currentSpatialLine.begin.position.x) / 2; int horizontalDirection = (transform.position.x - targetPosX) > 0 ? -1 : 1; Vector3 horizontalMove = HorizontalMove(horizontalDirection); if (horizontalDirection == -1) { if (horizontalMove.x > 0.0f) { horizontalMove.x = 0.0f; } } else { if (horizontalMove.x < 0.0f) { horizontalMove.x = 0.0f; } } lMovement += horizontalMove; Vector3 transformPosition = transform.position + lMovement; if (lMovement.x > 0.0f) { if (transformPosition.x > targetPosX) { //print("je tp >0"); lMovement.x = targetPosX - transform.position.x; } } else if (lMovement.x < 0.0f) { if (transformPosition.x < targetPosX) { //print("je tp <0"); lMovement.x = targetPosX - transform.position.x; } } } else if (currentSpatialSas == null) { Vector3 transformPosition = transform.position + lMovement; if (transformPosition.x < currentSpatialLine.begin.position.x) { lMovement.x = currentSpatialLine.begin.position.x - transform.position.x; } else if (transformPosition.x > currentSpatialLine.end.position.x) { lMovement.x = currentSpatialLine.end.position.x - transform.position.x; } } if (isChangingSpatialLine) { /*lMovement.z = (transform.position.z - currentSpatialLine.begin.position.z) > 0 ? -1 : 1; * lMovement.z *= moveSpeed;*/ int verticalDirection = (transform.position.z - currentSpatialLine.begin.position.z) > 0 ? -1 : 1; // on passe automatiquement la vitesse de déplacement vertical à la vitesse de course si on est poursuivi et qu'on va dans un casier/ascenseur if (needsCentering && !isRunning) { bool needsToRun = false; foreach (Enemy enemy in GameManager.instance.enemyList) { if (enemy == null) { continue; } if (enemy.isChasing) { print(enemy.name + " is chasing player."); moveSpeed = runSpeed; animator.SetBool("IsRunning", true); needsToRun = true; break; } } if (!needsToRun) { animator.SetBool("IsRunning", false); } } Vector3 verticalMove = VerticalMove(verticalDirection); if (verticalDirection == -1) { if (verticalMove.z > 0.0f) { verticalMove.z = 0.0f; } } else { if (verticalMove.z < 0.0f) { verticalMove.z = 0.0f; } } lMovement += verticalMove; Vector3 transformPosition = transform.position + lMovement; //print("movementz" + lMovement.z); if (lMovement.z > 0.0f) { if (transformPosition.z > currentSpatialLine.begin.position.z) { //print("je tp >0"); lMovement.z = currentSpatialLine.begin.position.z - transform.position.z; } } else if (lMovement.z < 0.0f) { if (transformPosition.z < currentSpatialLine.begin.position.z) { //print("je tp <0"); lMovement.z = currentSpatialLine.begin.position.z - transform.position.z; } } if (Mathf.Abs(transform.position.z - currentSpatialLine.begin.position.z) < 0.001f) { isChangingSpatialLine = false; } } else if (_horizontalAccDecLerpValue != 0) { lMovement += VerticalSlowDown(); } else if (_horizontalAccDecLerpValue != 0) { lMovement += VerticalSlowDown(); } rb.MovePosition(transform.position + lMovement); /*if (Mathf.Abs(hMove) < 0.01f && Mathf.Abs(vMove) < 0.01f) * { * isMoving = false; * }*/ } if (Mathf.Abs(lMovement.x) < 0.01f && Mathf.Abs(lMovement.z) < 0.01f) { isMoving = false; } animator.SetBool("IsMoving", isMoving); }
private void OnTriggerExit(Collider other) { CameraBlock camBlock = other.GetComponent <CameraBlock>(); if (camBlock != null) { if (currentCameraBlock == camBlock) { currentCameraBlock = null; } return; } if (other.GetComponent <SpatialSas>() != null) { currentSpatialSas = null; float zOffset = Mathf.Infinity; foreach (SpatialLine sl in currentSpatialRoom._spatialLines) { if (sl.begin.position.x <= transform.position.x && sl.end.position.x >= transform.position.x) { float offset = Mathf.Abs(sl.begin.position.z - transform.position.z); if (offset < zOffset) { zOffset = offset; currentSpatialLine = sl; isChangingSpatialLine = true; changingLineDirection = (sl.begin.position.z - transform.position.z) > 0 ? 1 : -1; } } } return; } if (other.CompareTag("Hideout")) { isHidden = false; } else if (other.CompareTag("Metal_Casier")) { overrideSurface = false; } else if (other.CompareTag("NeedsCentering")) { needsCentering = false; } else if (other.CompareTag("Elevator")) { Elevator elevator = other.GetComponent <Elevator>(); if (elevator != null) { isInElevator = false; elevator.isPlayerOnBoard = false; } } else if (other.CompareTag("DetectZone")) { Enemy e = other.GetComponentInParent <Enemy>(); e.DetectPlayer(false); } }
private void OnTriggerEnter(Collider other) { CameraBlock cameraBlock = other.GetComponent <CameraBlock>(); if (cameraBlock != null) { if (cameraBlock == currentCameraBlock) { return; } if (currentCameraBlock != null) { StartCoroutine(CameraBlockChangesCoroutine()); } currentCameraBlock = cameraBlock; CameraBlockChanges(); return; } SpatialSas spatialSas = other.GetComponent <SpatialSas>(); if (spatialSas != null) { currentSpatialSas = spatialSas; currentSpatialLine = spatialSas.spatialLine; isChangingSpatialLine = true; changingLineDirection = 1; return; } SpatialRoom spatialRoom = other.GetComponent <SpatialRoom>(); if (spatialRoom != null) { currentSpatialRoom = spatialRoom; if (currentSpatialSas == null) { chooseNearestSpatialLine(); } return; } else if (other.CompareTag("TriggerBipede")) { if (!triggerBipede) { triggerBipede = true; AkSoundEngine.PostEvent(GameManager.instance.triggerBipede1Sound, GameManager.instance.gameObject); } } else if (other.CompareTag("TriggerPorte")) { other.GetComponent <TriggerPorte>().SetSpeed(); } else if (other.CompareTag("Metal_Casier")) { overrideSurface = true; } else if (other.CompareTag("Hideout")) { isHidden = true; } else if (other.CompareTag("DetectZone")) { Enemy e = other.GetComponentInParent <Enemy>(); //e.DetectPlayer(true); //print("COLLISION ARAIGNEE"); } else if (other.CompareTag("Finish")) { AkSoundEngine.PostEvent("Stop_Random_Track1", GameManager.instance.gameObject); GameManager.instance.camHandler.DestroyTarget(); UIManager.instance.FadeInEnd(); } else if (other.CompareTag("Elevator")) { Elevator elevator = other.GetComponent <Elevator>(); if (elevator != null) { elevator.isPlayerOnBoard = true; elevator.StartMoving(); animator.SetBool("IsMoving", false); isInElevator = true; //print("elevator starts moving"); } } else if (other.CompareTag("NeedsCentering")) { needsCentering = true; } }