top of page

TTA330 Portfolio - Code

During my VR Experience project I had to learn the basics and some advanced coding in C#, on this page I will show some of this code and give explanations into what the code is doing. The explanations will be in the code as comments (This is formatted as follows: //"Comment"). I have done it this way to help show exactly what I am talking about in that part of the code. Most of this code I have learnt through following tutorials from Valem for the VR development portion (A VR/Unity YouTube creator) and Info Gamer for the multiplayer portion (A Unity YouTube creator). Once I had learnt basics on how to code from these tutorials I then implemented and edited code to get it to work exactly how I wanted it to so could work for my game. The Valem Discord server was also a great place to ask for advice and help when struggling with different parts of my game. I even found myself giving out advice towards the end of this module with what I had learnt! For my game, I ended up writing fourteen scripts as well as four extra for networking. Some of the scripts are short and some are much longer. These Images can be seen below

I have included a limited amount of code which is not to be copied. If you would like to see more or wish to collaborate on the project don't hesitate to contact me at bwsoundandlighting@gmail.com and I will be happy to share more!

This is the first script I created. It makes the game engine aware of the hand controllers and allows me to attach animated models to where the hands would be in real life.

This next script allows us to control the avatar and let it follow us when in VR. There are also some separate scripts and animations used to make the avatar look like they are walking and to make arm and body movements mimic real life. This is done with an animator, bone renderer and rig builder components as well as my VRFootIK and VRAnimatorController scripts.

This short piece of code shows how I used clever camera tricks to be able to show me from outside and inside the VR headset at the same time. I had to have 2 cameras in the scene. One pointing to one display and the VR headset and the other to a second screen. This is a tricky thing to do as the computer has to now render two displays as well as the VR headset display so you need to make sure to the game is well optimised for the computer to essentially run three instances of it. A high spec computer helps too! When I publish the game this code won't be included as I don't need to render all these extra scenes, however, it could be a cool addition for people on the outside of the VR headset to see what the person inside is doing. If I were to go this way I may need to think of an easier implementation of this feature.

The last piece of code I will show you is to do with getting the quickstart room to seamlessly transition to the multiplayer scene when the player is ready to join the multiplayer experience. As I said before, if you have any questions or would like to see more code in detail, don't hesitate to get in touch!

As talked about previously on the TTA330 Portfolio page, I had a few issues with multiplayer which I managed to rectify, however, one issue still stands. When in multiplayer the teleportation and some interaction won't work. I have tried many different methods to rectify this and have come to the conclusion that the XR Interaction Toolkit doesn't like being instantiated (which is needed when spawning new avatars for multiplayer. Instantiate in this context means to spawn something in that isn't already in the scene). I had a look at some forums and websites that also point to this however there is no fix I can find. I would love to fix this if I decide to publish it.

bottom of page