Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

[Infinity Series] Top-Down / 3rd Person Locomotion & Combat Tutorial & Demo Scene [Part 10 Posted]

Discussion in 'Community Learning & Teaching' started by infinitypbr, May 10, 2016.

  1. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    Infinity Series: Top-Down/3rd Person Locomotion & Combat Tutorial & Demo Scene

    I'm going to produce a tutorial series using a few of the Infinity Series assets. Specifically we'll be building a top-down scene using the Dungeon+ Pack PBR, and our player character will be the RPG Barbarian Pack PBR, using weapons from the Weapons & Armor Pack #1. There will also be chests from the Chest Pack PBR. Our enemies will be from the PBR Monster Pack #1.

    The Assets I'm using ARE NOT REQUIRED. You could easily do everything I'm doing with Assets you may already own, or with primitive objects -- sub a squished sphere on top of a cylinder for the Mushroom, for instance, and a capsule for the Human & another for his Sword. The scripts & concepts are the important thing here :)

    If you don't have these yet, you'll still be able to download the demo project, but you'll find missing prefabs etc if you do not have the assets already installed. If you do happen to have some or all of these packages, you can begin by starting a new project in Unity 5.3.4 or above*, and importing the models & demo textures from those packages into your scene. You do not need the .sbsar files, so please DO NOT import those, as they'll simply take up space and import time. You'll need to download the "DungeonDemos1v2.zip" from www.InfinityPBR.com (register with the Invoice Number from your Unity Asset Store receipt), and import Demo Scene #1.

    Screen Shot 2016-05-10 at 12.05.38 AM.png
    _______________________________________________________________________________
    The Format
    I prefer that students do not copy/paste the work. I will present each section via a Youtube video, where I discuss some of the key additions to the project. In most cases, I will also provide the most updated unity package for the project.

    Ideally, students will use the provided package only as a backup or reference, and will re-create the files by hand. Doing it by hand will help the brain recognize the patterns and syntax used.

    The videos will include actual speaking (in English), rather than text only. Hopefully they will be clear and concise. Let me know if you have any issues with them!

    _______________________________________________________________________________
    About Me
    I don't claim (at all!) to be the best programmer out there. I will be doing this in Unityscript, although the concepts should hold 1:1 to C#. It's likely best for those who are trying to learn to re-do the scripts themselves anyway, so that you get the experience of actually typing the code out.

    PS. I'm still going to complete the 1st Person RPG tutorial series I began a few months back. I started that when I had free time, and then free time went away! It'll continue when i get more free time.

    * it should working anything at or above 5.3.4, but i'm making it in 5.3.4

    _______________________________________________________________________________

    YouTube Videos
    (I'm also embedding these in the comments below, including some text about what the video is all about)
    #1: Introduction & Setup
    #2: Building the Scene
    #3: Character Locomotion
    #4: Interaction #1
    #5: Interaction #2
    #6: Enemy (AI) Movement

    #7: Enemy Melee & Casting
    #8: Player Melee Combat
    #9: Hit Boxes & Attached Magic
    #10: Audio Control
     
    Last edited: Oct 24, 2016
    Edmar Senne, TonyLi and frosted like this.
  2. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #1: Introduction & Setup

    In this video I basically show what packages I've installed into the new project, also where to go to get the Dungeon Demo package, which is required for the dungeon environment. Lastly, I create the directory inside the Assets/SFBayStudios/ folder where all of the tutorial files / scripts will be kept.

    Really this is an optional video :)


     
  3. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #2: Building the Scene

    In this speed video, I create the basic level, with some doors & levers to open them, a pit w/ a fog particle & a temporary character to move around it.

    It still needs work -- colliders, some more bits and pieces, but the basic is here.


     
  4. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #3: Character Locomotion
    Download Project Files
    This video begins with the updated level, with colliders on all the geometry and that good stuff.

    We then equip the human character (both male & female) with some clothing, and animate the character to run around, using mouse-click to move. Basically click on the screen and the character will run there, smoothly rotating around.

    I describe what I'm doing in the scripts as well.


     
  5. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #4: Interaction #1

    This starts a longer segment on interaction. Basically opening chests, switching levers and all that. Attached to it are things that happen when you open the chest or switch the lever.

    Eventually this "Interaction" section, broken up into multiple videos, will also include equipping the character, reflection probes & using a 2nd camera to show a close up of the weapon equip action.


     
    Alardaen likes this.
  6. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #5: Interaction #2
    Download Project Files

    Here I describe the changes I've made after the last video. We can now walk around and trigger the doors to open using the levers (one floor, one wall). Also, when we open the chest, a close-up cameras shows the player equipping the sword from his back.

    While it may not be the most efficient way to do it for larger, more complex games, for this small tutorial I've used a method of small single-purpose scripts to accomplish all this. Each one has a function called "Open", which is called via a Broadcast Message after an Event is triggered on the main animation.

    This allows us to do a lot of things only "On Open", similar to the onClick event system for the UI.


     
    Last edited: May 14, 2016
  7. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #6: Enemy (AI) Movement
    Download Project Files

    This video opens with a quick update to the last, and then I go through the process of setting up an enemy character. The nuts & bolts of the Rigidbody, collider & Nav Mesh Agent.

    Next, I walk through the scripts I wrote to control the movement of the Enemy. The Mushroom Monster will have both range (cast) and melee attacks, and the scripts control which attack is called, or none if the player is too far away.

    Hopefully the movement of the enemy will feel natural and realistic. To this point, I've also included a script that'll have the Monster walk backwards a bit if the player gets too close. Not only will this make the monster appear more real, but it will also add a small challenge to the player, who will have to time attacks to hit before the Monster walks away.


     
  8. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #7: Enemy Melee & Casting
    (I numbered the video wrong)
    Download Project Files

    This remarkably short video ( :D ) shows the implantation of a spell casting & melee attack system for the Mushroom Monster enemy.

    The casting has a particle, of course, and a collision detection system. The melee uses an "Attack Point", which is turned on/off by and animation event. When it collides with the player, it turns of an a "hit" is made.


     
  9. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #8: Player Melee Combat
    Download Project Files

    In this video, I go over a different way of doing attack checking. For the Mushroom Monster in the previous videos, we simply used collision. However, there's a potential for a player weapon to miss colliding with an enemy, if the weapon ends up before the collider in one frame, and after it in the next. Slower frame rates (like on mobile), or thin colliders (like on a skinny enemy), can easily make this happen.

    So instead, I use two "Weapon Points" on the player weapon -- one on the base, and one on the tip. During the "Attack Check" phase, we do a RaycastAll command on the line between the base & tip, and between the previous position of each and the current position of each.

    This creates a sort of "C" shape, and greatly increases the chances that enemies who fall into the zone between the sword on subsequent frames will still be found as "hit".

    I also use a Random Number variable to ensure that each enemy is only hit once during any given swing of the player weapon.


    =

     
  10. Kiwi-Hawk

    Kiwi-Hawk

    Joined:
    Jul 17, 2015
    Posts:
    286
    Great to hear about a scale after just after I bust my bank
     
  11. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    #9: Hit Boxes & Attached Magic
    No Project Files This Time

    There are two concepts in this video we go through. First is "Hit Boxes", which are simple collider objects attached to a character or enemy, which a weapon (among other things) can hit. The new boss monster, "Rock Monster", is large, and his main collider is as well. Similar to #8, the sword was often inside the entire collider, meaning it didn't connect with the edge, and therefore wouldn't "collide", even though to the player it should.

    The solution is to add Hit Boxes to various limbs, which are smaller. So we go over managing that. It's quite easy.

    Next, the magic attack of the Rock Monster is a big laser that shoots from his eye. Unlike the Mushroom Monster magic, which is a projectile, this is attached to his body. So we use a script for what I'm calling "Attached Magic", to shoot a SphereCast (similar to a RayCast) forward from that position. Other than that, it's the same logic as any other attack, but it's an important bit of code to keep around.

    In the next episode, we'll work on audio!


     
  12. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    Last edited: Oct 24, 2016
  13. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    448
    I completely missed these tutorials. I'll go through them when I get a chance. I appreciate you taking the time to make these.
     
  14. infinitypbr

    infinitypbr

    Joined:
    Nov 28, 2012
    Posts:
    2,629
    Cool -- I hope they're helpful. Unfortunately they were in .js I think ,and so they're not super helpful out the box, but I think some of the concepts are still workable.