BSA228 Week fourteen - Fixing Movement

Movement


On Monday I found out that my book is going through the ceiling and also the ground and of course that is not what I want. So I spent my class time on fixing this bug. I tagged the objects with ground and ceiling and added the methods OnCollisionEnter and OnCollisioExit to the move script, which is attached to my player. If it touches the ground or ceiling the up and down movement will be set to 0.0f so it will stop at the point. When the game Player presses the opposite key to it the player will move again.

So the script checks if the player is colliding with ground or ceiling and if it change the Boolean touchGround or touchCeiling into true. From the start they are false. And if the player exit out of the collider the Boolean is set back to its default.


Debug.Log

To make it easier for me to see if the method is working I added a Debug.Log to it and this will show in the Console of Unity.

Kommentare