Switching It Up and More

For over a week, I’ve been making serious progress into my game development. I successfully implemented all three goals of my goals – implementing all arrow restriction mechanisms (fire one arrow at a time, restricting teleportation to only trees, and increasing arrow travel speed), added a weapon switching mechanism with actual gun models, and shooting mechanism. I’ll briefly go over how I implemented each one.

Arrow restrictions:

I’d like to note that all arrow restrictions where done by modifying the SteamVR arrow scripts: these involved the ArrowHand.cs and Arrow.cs scripts. ArrowHand is responsible for spawning arrows in your dominant hand while Arrow takes care of arrow physics.

  • In ArrowHand.cs, I created a private static Boolean titled isArrowInAir with get and set methods to allow for modifications from external classes. In the ArrowHand.cs class, there is a method titled FireArrow which fires the arrow after it has been knocked on the bow. In this class, I set isArrowInAir equal to true and used this Boolean to restrict access to methods within the ArrowHand class, particularly the ones that spawn arrows and allow for bow interaction. In Arrow.cs, I set this variable to false when a collision occurs, which causes another arrow to spawn in the player’s dominant hand. Finally, there is another instance where isArrowInAir is set false in the TeleportPlayer.cs when the arrow times out.
  • For restricting teleportation access, I created a tag titled Tree, changed the tree prefab so that it was tagged as Tree, and modified the delegates so that they took a string as well. When a collision occurred, I then passed the tag on the object the arrow collided with into the delegate. In the method that was assigned to the onArrowLanded delegate in the TeleportPlayer script, I then check to see if the string passed in is equal to Tree. If it is, the player is teleported to the arrow’s location.
  • Increasing arrow speed was a simple fix – I just increased the public variable values in the longbow class.

Weapon switching mechanic:

  • I wrote a class titled WeaponSwitch which manages the entire game mechanic. To set it up, I began by attaching the guns onto the player’s hands and disabling them using Unity’s game design interface. When the game starts up, SteamVR uses a class titled ItemPackageSpawner to allow the player to pick up a bow and arrow instance in the game world. When a player picks up the bow and arrow, the actual bow and arrow items spawn in the players hand. I then initialize some class variables used to hold the longbow and the arrow hand since they have now spawned in the environment. To switch the weapons, I attached a cube collider to the back of the players head, and scripted a separate class titled CollisionChecker for each of the hand objects. When the player puts one of the hand controllers into the cube, it sets a static Boolean variable to true in the WeaponSwitch class, and then becomes false again once it leaves the cube. When both are set to true, the player can squeeze both grips, and the weapons are then switched by enabling the gun models and disabling the longbow and arrow models. Once the weapons are switched, a coroutine is activated for half a second which restricts weapon switching with a Boolean value.

Weapon Firing mechanic:

  • A very short script titled WeaponFire was developed and attached to each gun object. A bullet prefab, which for prototyping purposes is a gold, metallic colored cylinder, is instantiated when the player pulls the trigger on their hand controller at a bullet spawning location attached on the controller. Then, the Rigidbody component is taken, and its velocity is set equal to the vector representing the direction of the bullet spawning location’s z-axis (its forward) and multiplied by a public float variable representing speed. Outside of the script, I attached a Trail Renderer component to my bullet prefab to create a tracer effect. If you’re interested in your own tracer effect, here is a link to the tutorial I used.

Here’s a video demonstrating the current implementation I have. There’s only audio for the bow and arrow, because since I am using a modification of SteamVR’s finished bow and arrow classes, it already has sound effects.

Finally, I almost got halfway through the Puzzle Ball game I’m making in Unity. I didn’t get all the way through due to extraneous time working on the arrow restrictions, but I hope to find time to complete it sometime this week. I do believe completing it will be beneficial to my game development goals for this week, as we will be going through some AI development in this section, and I have a goal this week where I will be implementing a navigation mesh system to have enemies track the player.

Goals for this week:

Note: some of the development goals I set in the initial game design document must be pushed back, as I am slightly off schedule. However, I am still on track to complete the prototype by the July 8th deadline.

  • Finish monster assets to use, and implement a monster generation system that paths to you.
    • Estimated date of completion – 6/29/2017
  • Script player health, monster health, and monster damage
    • Estimated date of completion – 7/1/2017
  • Finish Puzzle Ball section of my Unity coursework, and if extra time, start next week’s content.

Leave a Reply

Your email address will not be published. Required fields are marked *