CaydenJessen / Stay-Hidden_GAME

Game Repository for CRE311
0 stars 1 forks source link

Game Freezes the Camera and Player randomly. #9

Closed AndyLee-SH closed 1 month ago

AndyLee-SH commented 1 month ago

Describe the bug When playing the game a few times, the game freezes the camera and the player. Solution is to restart unity or reopen the scene.

To Reproduce Steps to reproduce the behaviour:

Player goes through the game multiple times Player interacts with NPC When the player replays the game and goes through the same scene, the camera and player freezes.

Desktop (please complete the following information):

OS: Windows 10 Unity Version 2022.1.7

CaydenJessen commented 1 month ago

The problem revolved around a isAlive boolean value which detects whether the player is alive or not (which is set true if their health is above and false if it is 0 or below). If this value is true it freezes the player and camera transform/movement.

This isAlive check was only called when the player collides and takes damage from the enemy. If the player plays the game and touches the enemy it makes this check to see if the player is alive. The next time the player plays the game it instantly sets isAlive to false and the player health to negative, freezing the player and the camera.

To fix this I moved this isAlive check into the Update() method so that it constantly checks if the player is alive rather than only checking when the player takes damage.