Dev Blog

Monkey Mayhem – Dev Log 06

By October 16, 2018 No Comments

Welcome back to another development log.

In the days since I last posted, We’ve started to bring the game together. Chris has managed to complete the procedural generation section of the game which means we can start testing the players properly. I had some problems with the player controller which I’ll go into detail in a bit.

To remind you where I left off, here’s the last gif.

Trampolines, Cameras and Rotations

So the first thing i did this week was add in some trampolines for the players to bounce off and the cameras for the individual players.

The trampolines script was pretty simple. I added a cube to the scene and then scaled it to fit the level. I then added the following as a script:

void OnTriggerEnter(Collider col)
    if(col.gameObject.tag == "Player")
        col.gameObject.GetComponent<Rigidbody>().AddForce(direction * force, ForceMode.Impulse);

Basically, it checks to see if the player has entered the collider, if it has it will add a force in the direction of the direction variable. This means I can use the same script for the side trampolines too.


For the Cameras, I decided to use the Unity package Cinemachine. Cinemachine allows for procedural camera rigs with little code.

The first thing I did was add in a second camera. To the two camera’s I added Cinemachine Brains, this component allows Cinemachine Virtual Cameras to be displayed through them. I then added two Virtual Cameras to the scene.

The only problem now is that both cameras are displaying the same Virtual Camera. The way I fixed this was by changing the layers and culling masks on the cameras. I created two layers, P1Cam and P2Cam, and set the relevant cameras to the layers. I then changed the Cinemachine Brain’s culling masks on the Cameras, to not include the other players layer in the culling mask. The result is a split screen view with the added bonus of all the cool things Cinemachine can do, such as damping and confining.

The final thing I did this week was sort out a problem with the player. If the player was to use the trampoline for a while, its rotation matrix would change which meant when it attached to the branch again it wouldn’t be able to swing. Look at the gif below for more information

So now we know the problem, what’s the solution?

Well after a couple of days of trying different methods like adding constraints to the rigidbody. My tutor suggested just resetting the rotation matrix to conform with the hinge constraints. So in the end it was as simple as this:

Quaternion newRotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z);
transform.rotation = newRotation;

We just change the x and y rotations to 0 and set the current z angle to the one we already have. Simple!

So after putting everything together, the final result for the past couple of days can be seen below

That’s all for this post

See you next time,


Leave a Reply