Today, Mr. Wong instructed us to begin thinking about our "final project." It can generally be on anything tech-related that interests us. I have decided to make a game using Unity for this project. During the Hour of Code, a lot of classes signed up for VR. I've had a Quest 2 for a while, and seeing all of the games and apps being used during the event made me want to try to create a VR game. Last Sunday, I opened up Unity and began making a quick scene, following tutorials to get VR working. To use VR in Unity, I enabled the use of OpenXR in the project's settings. I then used the package manager to import the XR Toolkit, which came with pre-made input maps. This is helpful, as I am still learning Unity's new action-based input system. I then placed an XR Origin, which is basically where the player and their hands are. There is built-in functionality for moving and rotating. Picking things up is also done through "interactor" and "interactable" components. There is an older, depricated version of Unity's XR integration. A lot of online tutorials were using it, and there were only a few that worked with the latest one. Regardless, I eventually figured out how to add hands and make them able to pick up objects. You probably noticed the red lasers emitting from the hands. When the XR Rig is initially placed, the hands are given "XR Ray Interactors" which allow you to pick up objects in a straight line. The red line is the default representation of this line. I added a little script to toggle the visibility of the lines. The InputActionReference is a reference to a button specified in that action map I imported earlier on (which happens to be the "y" button on the Quest 2). The XRInteractorLineVisuals are the lasers. When the script runs, it subscribes to the action's "performed" event. This means whenever the button is pressed, it runs the ToggleLasers function, which just switches the XRInteractorLineVisuals on or off. The Drum SetToday, I wanted to see if I could add a drum set to the project. I first made a 3D model in Blender. Each part is its own object, which makes handling collisions in Unity Easy. I imported the model and resized it in Unity. I wanted to make each part of the drum light up when hit (as well as play it's noise). To do this, I first made a shader using Unity's Shader Graph tool. Unity's Shader Graph is kind of similar to materials in Unreal Engine, so I was easily able to make a shader. It took me a while to get the whole system working. First, in order to set the 'hit parameter' (which when set, makes the drum flash colors) I had to set it via a 'reference' name, which the shader automatically generated. Also, some of the models have messed up geometry, so their mesh colliders are way to big. I didn't really want to fix it at the moment though, as the colliders wouldn't get in the way of anything else. Finally, I found a free pack of drum sounds, and added them to each drum piece via an array within the drum part script. And after a lot of troubleshooting, the drum set worked! I unfortunately don't have a picture of it working (as I can't really take a screenshot on my computer when using both hands in VR), but trust me, it really does work.
However, I have a video of it all working on my school's drive. You can find it here. (You may notice that the drums tend to play more than once when hit. I believe the fix is to make each drum piece a seperate Rigidbody rather than have none at all, which is what I initially had set up. At the time of recording, I did not implement this.)
0 Comments
|