/// <summary> /// Handles the collision check with the memento, picking it up and /// changing the enemy state to TransportingMemento /// </summary> /// <param name="collider"> Collider: collider that is now colliding with this enemy</param> void OnTriggerEnter(Collider collider) { /* This code feels dirty. * Memento's trigger collider is on the child object, so we need * to access its parent through its transform */ Transform parent = collider.gameObject.transform.parent; if (parent != null && parent.tag == "Memento" && NEST != null && NEST.MEMENTO == null && (_enemyState != EnemyState.TargetingPlayer && _enemyState != EnemyState.TransportingMemento)) { _memento = parent.gameObject.GetComponent <Memento>(); _memento.Bind(this.gameObject); ChangeState(EnemyState.TransportingMemento); _navAgent.SetDestination(NEST.transform.position); } }
/* * CB: I've moved the code related to inputs into an Update. * * This is to hopefully solve the dash and door not always working */ void Update() { /* X-Ray Button Handler */ if (_player.GetButtonDown("Xray")) { /* The actual code for spawning an x-ray portal is in XRayPortalControl.cs */ if (_memento != null) { _memento.OnPlayerAbilityUsed(); } } /* Dash Button Handler */ if (dashReady && _player.GetButtonDown("Dash")) { GameObject trail = Instantiate(RemDashTrail, transform); trail.SetActive(true); if (_memento != null) { _memento.OnPlayerAbilityUsed(); /* This code shoots a raycast from the memento forward, attempting to check preemtively * if the player is going to pass through a wall when dashing. This is needed to solve * the issue where the memento is already in a collision with the wall when the dash * occured, as the memento was not triggering a second collision. */ RaycastHit hitinfo; Physics.Raycast(_memento.transform.position, this.transform.forward, out hitinfo, 1f); if (hitinfo.collider != null && hitinfo.collider.tag == "Wall") { //Debug.Log("Preemptively dropping the memento"); DropMemento(); } } _isDashing = true; //Get "forward" and "right" from the perspective of the camera. Used by OTS Camera. Vector3 cameraForward = OTS_CAMERA.transform.forward; Vector3 cameraRight = OTS_CAMERA.transform.right; cameraForward.y = 0f; cameraRight.y = 0f; cameraForward.Normalize(); cameraRight.Normalize(); float inputHorizontal = _player.GetAxis("MoveHorizontal"); float inputVertical = _player.GetAxis("MoveVertical"); //float inputRHorizontal = Input.GetAxisRaw("RHorizontal"); //float inputRVertical = Input.GetAxisRaw("RVertical"); switch (_view) { case VIEW.OTS: dashForce = cameraForward * inputVertical + cameraRight * inputHorizontal; dashForce = dashForce.normalized; break; case VIEW.TD: dashForce = new Vector3(inputHorizontal, 0, inputVertical); dashForce = dashForce.normalized; break; } _audioSource.Play(); /* Play the dashing audio clip */ dashReady = false; // CB: Added this back, as it is used to determine if the player is allowed to dash, not just if the effects have ended StartCoroutine(StopDashEffects()); DASH_NOT_READY_ICON.SetActive(true); StartCoroutine(DashCountdown()); } /* Interact Button Handler */ if (_player.GetButtonDown("Interact")) { StartCoroutine(OpenDoors(this.gameObject.transform.position, INTERACT_RADIUS)); } /* Drop Button Handler */ if (_player.GetButtonDown("Pickup/Drop")) { //StartCoroutine(OpenDoors(this.gameObject.transform.position, 5.0f)); // CB: Dropping a memento shouldn't open doors if (_memento != null) { if (_held == false) { _memento.Bind(this.gameObject); _held = true; } else { DropMemento(); // CB: Moved memento dropping into one method _held = false; } } } /* Reload Button Handler */ if (Input.GetKeyDown("r")) { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } /* Camera Toggle Button Handler */ if (Input.GetKeyDown("v")) { if (_view == VIEW.OTS) { EnterViewTD(); } else { EnterViewOTS(); } } }