This week in class we shared with other students what everybody had done so far and learned some techniques we could use to help with creating our game. Some of the techniques included how to create a destructible wall, how to track the ball when it is above the ground and how to make quick map terrains. The destructible wall was ingeniously simple, creating an empty gameobject which has child cube objects that make up the wall, these cubes have rigidbodies attached to them but are set to kinematic. The parent gameobject then has a collider and a script to detect when the collision with the player happens. When the collision happens the script iterates through all the children of the gameobject and sets the rigidbody to no longer be kinematic. I had previously wondered about how I was going to implement destructible objects into the game and found this solution to be extremely easy to understand and easy to implement and planned to add it to my game.
This week I was setting out the first level, my main concern was with the level and how I was going to populate the level with GameObjects. The problem was with getting the actual world x, y and z positions to spawn the object at, I had previously only worked on flat surfaces so spawning objects were easy as the Y location was constant, however with a sloped surface the Y location is constantly changing. I thought that there would be a way to calculate the Y location at a certain point along the object, but haven’t found one as of yet. Another way I thought I could work out this problem is by using a series of angular calculations of initial position and Z distance travelled to figure out the Y valueof the current location. The solution I found in the end was to implement raycasting, setting up two GameObjects above the level and using that as the X and Z values while raycasting down to the slope to get the Y value, this solutions does exactly what it needed to do.
After figuring out how to determine the Y location at any given point in the slope the next step was how to populate the level with objects. I accomplished this using the two GameObjects that were previously mentioned, creating a simple for loop that begins at one GameObject’s Z value and ends when it reaches the other other GameObject’s Z value it terminates. The increment value is set as a public variable so that we are able to easily change the density of the level. Another consideration I found had to be made was to ensure that the objects should be rotated with the slope, I made the slope rotation a variable as I was planning to change it in the later levels. Finally selecting the entity to add to the level was the easiest part of this whole problem, simply adding a list of Trap, Pickup, and Enemy objects and randomly selecting between them.
In conclusion this week I’ve compared myself to other students in terms of progress on the assignment and I’ve identified that I’m behind and should try to work more this week on the assignment. I learnt a few techniques to help me create destructible objects which I will definitely implement in my game due to its simplicity and effectiveness. I managed to work through a problem, exploring multiple different solutions and finally coming to a working answer, not to mention this is a large part of the game as it is responsible for populating the game level. Overall a bit of a wake-up call of a week, but still relatively productive.