Search Unity

[1st Person RPG Tutorial Series] InfinityPBR.com [Episode 15 is Up! Unity Project Included!]

Discussion in 'Community Learning & Teaching' started by infinitypbr, Jan 13, 2016.

  1. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    InfinityPBR.com Presents
    First Person RPG Tutorial
    My favorite game ever is Might & Magic VI, from 1998. It's a 1st person RPG with a, for it's time, unique system of real-time exploration and turn-based fighting. Now that I make games and stuff, my eventual goal is to make an RPG with many of the same features/style present in M&M6.

    I figured I should make sure I do things as well as possible, and help people who are like I was a few years ago when I started with Unity, by making a Tutorial series on it.

    Some notes, however: I'm not the best coder. I currently use Javascript/Unityscript. I know Unity wants us all to do C#, and something like 80% or more of us do. But not me yet. I'm slowly learning, but since I'm faster in Unityscript, I'm sticking with that for these. However, I'm convinced that for most people, re-writing tutorial code is extremely helpful to the learning process. So I encourage anyone who is a C# coder, anyone who is new and looking to learn from these tutorials, to translate the code into C#. It'll take more time, but it'll be well worth it. Either way, I hope you'll find the logic to be sound.

    Let me know if you have any questions or comments or find any bugs! Obviously there are many ways to do things, and this is only one. I don't claim that it's the best, or most efficient. But hopefully you'll find it to be fairly efficient and light weight, and flexible. Enjoy!

    CURRENT TUTORIALS:
    1. Time Control
    2. Player Movement
    3. Mobile Joysticks
    4. Saving & Loading #1
    5. Saving & Loading #2
    6. Saving & Loading #3
    7. Character Creation Scene
    8. Saving & Loading #4
    9. Enemy Control #1
    10. Enemy & Projectiles, Save & Load
    11. Player Turn Based Actions
    12. Click/Touch to Attack
    13. Player Portraits
    14. Items & Inventory #1
    15. Items & Inventory #2
     
    Last edited: Feb 12, 2016
  2. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #1: Time Control
    http://www.infinitypbr.com/1stPersonRPG/timeControl.php <--Download Unity Package
    This is a package that includes a few scripts and a demo scene. The "Time Controller" object in the demo will keep track of in-game time, but only while the menu is inactive and the "t" button is not being pressed. The concept is that while we want the in-game time to progress as the player explores the world, we want it to pause while the player is using the menu, or for other reasons.

     
    Last edited: Jan 16, 2016
  3. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #2: Player Movement
    http://www.infinitypbr.com/1stPersonRPG/playerMovement.php <--Download Unity Package

    This package expands on the first and adds a "Player Object" with simple movement controls. The RPG I'm looking to build doesn't require physics for the movement, so we use a Character Controller. Keyboard/Mouse movment/looking in a lightweight package. We also add the Game Controller object with gameControl.js script to manage whether the game is paused or not (different from the time-keeping pause from the last tutorial).

     
    Last edited: Jan 16, 2016
  4. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #3: Mobile Joysticks
    http://www.infinitypbr.com/1stPersonRPG/playerMovement.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    In this package, we add in a dual joystick for mobile with plenty of options for various scenarios, all of which can be turned on/off by you, or if you expose the options, by your players. Options include, among others, finger-follow for the joystick sprites, the abilty to always show or always hide the sprites when not being used, resizing the joysticks for larger screens and more.


     
  5. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #4: Saving & Loading #1
    http://www.infinitypbr.com/1stPersonRPG/savingAndLoading1.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    This is a quick video on one of the most important topics: Saving & Loading! We produce a simple save & load script, which we can see clearly can be modified in the future to become a robust AAA quality save/load system, potentially including online uploads of saved games so users can play their games on multiple devices.

    Most of the stuff in this tutorial is taken from a Unity live training session with Mike Geig. Please check out the original here: https://unity3d.com/learn/tutorials...ining-archive/persistence-data-saving-loading

     
  6. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #5: Saving & Loading #2
    http://www.infinitypbr.com/1stPersonRPG/savingAndLoading2.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    I've expanded the saving & loading (As well as cleaned up the code a bit), to include a main menu screen that allows a player to start a new game (temporarily bypassing any character creation screen), as well as load a previous game from a list of saved games.

    The player can save the game once they're playing, and of course will start there, with the proper time and data, when they load the game again. Becuase the project is getting more complicated now, often there will be things that I know I'll be removing later.


     
    Last edited: Jan 18, 2016
  7. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #6: Saving & Loading #3
    http://www.infinitypbr.com/1stPersonRPG/savingAndLoading3.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    The nut of this update is the Character Creation test scene. In it, you can modify the data in a netsted class variable that holds a ton of info about the game, then save that one class & reload the information back into the class. I think this way of doing it is spot on, and will help tremendously going forward.

    There are also some other clean-up improvements, reducing the number of variables, creating more static variables when appropriate, and making links to UI.Text elements be of that type rathe than GameObject.


     
  8. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #7: Character Creation Scene
    http://www.infinitypbr.com/1stPersonRPG/characterCreationScene.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    This package (** Same as the "Saving & Loading 4", which follows this episode **) improves the Character Creation scene. While it's not yet finished, the majority of the nuts & bolts are in place, allowing players to choose gender, race, class, skills & bonus stat points.

    Classes, including lots of netsting, is used heavily now, and there's some pretty (clever, for me) good functions that make the entire process pretty streamlined.


     
  9. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #8: Saving & Loading 4
    http://www.infinitypbr.com/1stPersonRPG/savingAndLoading4.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    The two big improvements here are the "Entrance" objects, which are basically the triggers to move from one scene to another, and saving a screenshot of the game view whenever a user saves their game. Both are fun and important :)

    The entrace script allows for "required objects", so a player maybe needs to have a special object in their inventory in order to use the entrance. It also will (once I code it) allow you to prompt user for entry, such as "Do you really want to go into the dungeon?", or not. Finally, it allows you to force the start position in the next scene (or not, if you don't want to).

    When the user saves, a screenshot is taken, and then on the game preview panel from the main menu it's displayed. This will help users with lots of saved games remember which one they wanted to play.

    ** The package here is the same as the previous episode! **


     
  10. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #9: Enemy Control 1
    http://www.infinitypbr.com/1stPersonRPG/enemyControl1.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    Our "Enemy Control" is an object populating scenes which helps us load enemies when we enter a scene. We create new classes, and have an "Enemy" class for storage of off-line enemy data (like a database holding all the possible enemies), and a "SceneEnemy" class that holds in-game enemy instance data.

    Ultimately this allows us to fairly easily populate the scene with enemies which, when respawned, may be differnet than their previous versions.

    This package doesn't get into saving position/rotation/status yet, but the stage is set for those. Because the scripts are getting long, I'll no longer print them out here. Instead, download the package and check out the scripts inside Unity!


     
  11. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #10: Enemy & Projectiles, Save & Load
    http://www.infinitypbr.com/1stPersonRPG/enemyProjectileSaveLoad.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    We can now save and load the position and rotation of each enemy object, as well as the position and rotation of any particle object.

    There's some new classes for the particles, as well as some simple scripts to help manage the particles. Because the scripts are getting long, I'll no longer print them out here. Instead, download the package and check out the scripts inside Unity!


     
  12. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #11: Player Turn Based Actions
    http://www.infinitypbr.com/1stPersonRPG/playerTurnBasedActions.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    We have changed the movement controls a bit, so now you move with the arrow keys (with options to strafe and tilt the camera). We also have "player portraits" on the screen UI to use in the future. Right now they include an "Action signal" that is green when the player can do an action and red if the player is recovering from their last action.<P>

    In turn based mode, the script will select the player or enemy that is next able to do an action, and wait for the action to complete. For enemies, it's relatively automated. For players, the user has to select an action to keep the game moving along.


     
  13. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #12: Click/Touch to Attack
    http://www.infinitypbr.com/1stPersonRPG/clickTouchToAttack.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    A small but fun and important update, we now can click or touch enemies to attack them. This should work in both turn based and real time, but while you can still attack using the buttons, clicking on an enemy will attack them or shoot them with the range weapon if they're in range. Works in touch, which is nice :)

    Because the scripts are getting long, I'll no longer print them out here. Instead, download the package and check out the scripts inside Unity!


     
  14. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #13: Player Portraits
    http://www.infinitypbr.com/1stPersonRPG/playerPortraits.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    Now we set up our portraits! These are the real-time renders of the players shown in the boxes at the bottom of the screen, as well as the full-body image shown in our new "Inventory" panel. We use cameras & render textures with the UI Raw Image component to do this. We also use layers to fully separate these cameras & objects from the rest of the scene.


     
  15. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #14: Items & Inventory #1
    http://www.infinitypbr.com/1stPersonRPG/itemsAndInventory1.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    We set the stage for storing a list of all the items available in the game, as well as storing an inventory of items for each player. While there's more to flesh out, this is a good start, and it includes logic to give players items at the start of a new game based on the skills they have chosen, such as a "Short Sword" if they choose a sword skill.

    A "Short Sword" prefab has been added, made up of primitives, since we want to be able to see the equipped weaopns on the characters, as well as use a physical model for each item for pickups & the inventory screen.


     
  16. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #15: Items & Inventory #2
    UPDATED: See next post for details

    (Note: The bug I mention in the video may be fixed. I haven't been able to figure out how to reproduce it, so I'm not 100% sure...but after making the video, I re-did one function that may have fixed it.)

    Now the inventory screen has a grid for each player, where their items are stored. They can click and drag the items to a new spot on the grid, to another players portrait to transfer, or to their large portrait to eqiup. Once equipped, players can click the equipped object and drag it to their inventory to remove it, or transfer it to another player.

    This video doesn't go over every detail, because there's simply too much. Even I'm confused!! In all liklihood, as I add more features for other types of items, I'll end up refining the code and cleaning it up.

    This was one thing that I didn't know how to do before I started, so I was making it up as I went. I restarted a few times, and 5 days later this is the result. That type of coding practically begs us to redo it later, when we've got a clearer understanding of what we're trying to accomplish, and when other aspects of the entire project are more fleshed out.


     
    Last edited: Aug 31, 2016
  17. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,973
    #15: Items & Inventory #2 [Updated]
    http://www.infinitypbr.com/1stPersonRPG/itemsAndInventory2.php <--Download Unity Package
    ** It's likely best to start a new project with this package as enough as changed. **

    The Bug I mention in the previous video was *not* fixed, but I think it is now. The bug would occur when an object was equipped, then equipped again. Turns out that when I removed an object, I had simply set the name of the equipped object to null. So when we equipped another object, the script thought that the first object was still equipped -- it wasn't looking for the name, just whether an object was equipped or not in that spot.

    The solution was to set the "equipped object spot" to an empty class variable. This seems to have fixed it. Hopefully it doesn't cause more bugs :)

    The last project upload has been updated.