/* * FUNCTION: Controls camera movements * CALLED BY: FixedUpdate() */ private void CameraMain() { fCameraDistance = Mathf.Lerp(fCameraDistance, fCameraLerpValue, Time.deltaTime * 1.5f); fCurrentCamDir = Mathf.Lerp(fCurrentCamDir, -hControllerScriptCS.getCurrentPlayerRotation() + 90.0f, Time.deltaTime * 4.0f); tCamera.localEulerAngles = new Vector3(fCameraRotationX, fCurrentCamDir, fCameraRotationZ); v3CamDirection = rotateAlongY(new Vector3(-1, 0, 0), -hControllerScriptCS.getCurrentPlayerRotation()); if (iCameraState == 1) //regular gameplay { fCameraLerpValue = 35; //maintain a static distance between camera and the player tCamera.position = new Vector3(tPlayerMesh.position.x + v3CamDirection.x * fCameraDistance + fCameraPositionX, Mathf.Lerp(tCamera.position.y, tPlayerMesh.position.y + fCameraPositionY, Time.deltaTime * 70), Mathf.Lerp(tCamera.position.z, (tPlayerMesh.position.z + v3CamDirection.z * fCameraDistance), Time.deltaTime * 50)); } else if (iCameraState == 2) //Camera on death { fCameraLerpValue = 60; //increase the distance between the camera and the player tCamera.position = tPlayerMesh.position + v3CamDirection * fCameraDistance; tCamera.position = new Vector3(tCamera.position.x, tCamera.position.y + 30, tCamera.position.z); //increase the height of the camera //change the camera angle (look at the death scene) tCamera.localEulerAngles = new Vector3(Mathf.Lerp(tCamera.localEulerAngles.x, 40, Time.deltaTime * 25), tCamera.localEulerAngles.y, tCamera.localEulerAngles.z); } //make the camera shake if the fCamShakeImpulse is not zero if (fCamShakeImpulse > 0.0f) { shakeCamera(); } }
void FixedUpdate() { if (hInGameScriptCS.isGamePaused() == true) { return; } //set the position of guard in current frame tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x - fEnemyPosition), Time.deltaTime * 10), tEnemy.position.y, tEnemy.position.z); if (!hControllerScriptCS.isInAir()) //follow the player in y-axis if he's not jumping (cars cant jump) { tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, tPlayer.position.y + fEnemyPositionY, Time.deltaTime * 8), tEnemy.position.z); } //ignore y-axis rotation and horizontal movement in idle and death state if (iEnemyState < 4) { tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y, Mathf.Lerp(tEnemy.position.z, tPlayer.position.z, Time.deltaTime * 10)); tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, -hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z); } if (iEnemyState == 1) //hide the chasing character { fCosLerp += (Time.deltaTime / 10); fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 45, Mathf.Cos(fCosLerp) / 1000); if (fCosLerp >= 0.7f) { fCosLerp = 0.0f; iEnemyState = 0; hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren); } } else if (iEnemyState == 2) //show the chasing character { hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.Siren); fCosLerp += (Time.deltaTime / 4); fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX, Mathf.Cos(fCosLerp)); if (fCosLerp >= 1.5f) { fCosLerp = 0.0f; iEnemyState = 3; } } else if (iEnemyState == 3) //wait for 'fChaseTime' after showing character { if ((Time.time - fStumbleStartTime) % 60 >= fChaseTime) { iEnemyState = 1; } } //DEATH SEQUENCE else if (iEnemyState == 4) //on death { //to ensure correct rotation animation tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, 350, tEnemy.localEulerAngles.z); hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.TiresSqueal); iEnemyState = 5; } else if (iEnemyState == 5) //pin behind the player { fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 20, Time.fixedDeltaTime * 50); //vertical position after skid tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y, Mathf.Lerp(tEnemy.position.z, tPlayer.position.z + 20, Time.deltaTime * 10)); //horizontal position after skid tEnemy.localEulerAngles = Vector3.Lerp(tEnemy.localEulerAngles, new Vector3(0, 260, 0), Time.deltaTime * 10); //90 degree rotation if (tEnemy.localEulerAngles.y <= 261) { iEnemyState = 6; } } else if (iEnemyState == 6) { hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren); } } //end of Update
void FixedUpdate() { if (hInGameScriptCS.isGamePaused() == true) { return; } //set the position of guard in current frame /* * tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x - fEnemyPosition), Time.deltaTime*10), * tEnemy.position.y, tEnemy.position.z); */ Matrix4x4 mat = new Matrix4x4(); mat.SetTRS(new Vector3(0, 0, 0), Quaternion.Euler(new Vector3(0, -hControllerScriptCS.getCurrentPlayerRotation(), 0)), new Vector3(1, 1, 1)); Vector3 pos = mat.MultiplyVector(new Vector3(-fEnemyPosition, 0, 0)); tEnemy.position = new Vector3(Mathf.Lerp(tEnemy.position.x, (tPlayer.position.x + pos.x), Time.deltaTime * 10), tEnemy.position.y, // Mathf.Lerp(tEnemy.position.y, (tPlayer.position.y - pos.y), Time.deltaTime*10), Mathf.Lerp(tEnemy.position.z, (tPlayer.position.z + pos.z), Time.deltaTime * 10)); if (!hControllerScriptCS.isInAir()) //follow the player in y-axis if he's not jumping (cars cant jump) { tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, tPlayer.position.y + fEnemyPositionY, Time.deltaTime * 8), tEnemy.position.z); } else { RaycastHit hitInfo; if (Physics.Linecast(tEnemy.position + new Vector3(0, 20, 0), tEnemy.position + new Vector3(0, -100, 0), out hitInfo, (1 << LayerMask.NameToLayer("Terrain_lyr")))) { tEnemy.position = new Vector3(tEnemy.position.x, Mathf.Lerp(tEnemy.position.y, hitInfo.point.y + fEnemyPositionY, Time.deltaTime * 8), tEnemy.position.z); } } //ignore y-axis rotation and horizontal movement in idle and death state if (iEnemyState < 4) { // Vector3 pos = mat.MultiplyVector(new Vector3( 0, 0, 0)); //tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y, Mathf.Lerp(tEnemy.position.z, tPlayer.position.z, Time.deltaTime*10)); tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, -hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z); } if (iEnemyState == 1) //hide the chasing character { fCosLerp += (Time.deltaTime / 10); fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 45, Mathf.Cos(fCosLerp) / 1000); if (fCosLerp >= 0.7f) { fCosLerp = 0.0f; iEnemyState = 0; hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren); } } else if (iEnemyState == 2) //show the chasing character { hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.Siren); fCosLerp += (Time.deltaTime / 4); fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX, Mathf.Cos(fCosLerp)); if (fCosLerp >= 1.5f) { fCosLerp = 0.0f; iEnemyState = 3; } } else if (iEnemyState == 3) //wait for 'fChaseTime' after showing character { if ((Time.time - fStumbleStartTime) % 60 >= fChaseTime) { iEnemyState = 1; } } //DEATH SEQUENCE else if (iEnemyState == 4) //on death { //to ensure correct rotation animation tEnemy.localEulerAngles = new Vector3(tEnemy.localEulerAngles.x, 350 - hControllerScriptCS.getCurrentPlayerRotation(), tEnemy.localEulerAngles.z); hSoundManagerCS.playSound(SoundManagerCS.EnemySounds.TiresSqueal); iEnemyState = 5; } else if (iEnemyState == 5) //pin behind the player { fEnemyPosition = Mathf.Lerp(fEnemyPosition, fEnemyPositionX + 20, Time.fixedDeltaTime * 50); //vertical position after skid // tEnemy.position = new Vector3(tEnemy.position.x, tEnemy.position.y, // Mathf.Lerp(tEnemy.position.z, tPlayer.position.z + 20, Time.deltaTime*10));//horizontal position after skid tEnemy.localEulerAngles = Vector3.Lerp(tEnemy.localEulerAngles, new Vector3(0, 260 - hControllerScriptCS.getCurrentPlayerRotation(), 0), Time.deltaTime * 10); //90 degree rotation if (tEnemy.localEulerAngles.y <= 261) { iEnemyState = 6; } } else if (iEnemyState == 6) { hSoundManagerCS.stopSound(SoundManagerCS.EnemySounds.Siren); } } //end of Update