Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Tuesday, March 12, 2019

NPC Quest Giver Tutorial

This tutorial will cover creating an NPC Quest Giver using Unity, C#, and Mixamo. We will have an NPC that wanders along a path and can be interrupted by the player approach.

NPC Quest Giver
This tutorial will build off the core functionality from the Patrolling Enemy tutorial.
Modify the Spotted Functionality
  1. When the NPC spots the player, she should stand still instead of following the player
  2. Instead of an attack animation, we will import a friendly “talking” animation from Mixamo
  3. Import the new animation, and add it to the Animator Controller for the character
  4. Remove the Attack animation and Trigger, setup the Talking animation as before, with a Trigger called “Talk” to transition to the Talking animation
  5. Change the Animation trigger in the script
  6. We also want to stop the character from returning to her patrol, so we will add a bool at the top called “talking”
  7. And check for that bool  in our distance check in Update
  8. We’ll also add OnTriggerExit to set the character back to her patrol
  9. It would also help if she looks at us while she’s talking
  10. Lastly, add popup text for the NPC’s dialogue using GameObject > UI > Text
  11. Decide what your Quest Prompt should say, and remember to bind the text object’s Rect Transform to the bottom of the screen
  12. Disable the text object by default, we will toggle it on from the script
  13. Add using UnityEngine.UI to the top of the script and make a public GameObject for the quest text
  14. Set the QuestText true and false in the appropriate places
  15. Drag the QuestText to the empty GameObject slot on your character
  16. Be sure to test!
Quest Items and Activating the Quest
  1. Create a new C# script for the Quest Item (QuestItem.cs)
  2. Find a model to use as the Quest Item and give it a BoxCollider marked as IsTrigger, be sure the collider goes around the entire object
  3. Attach the QuestItem script to the object
  4. In the QuestItem script, add the OnTriggerEnter function
  5. Create a public bool to keep track if the player has collected the item
  6. If the colliding object is the player, set that tracking bool to true
  7. Back in the character’s script, we need a bool to keep track if the quest item was found
  8. And we need a public QuestItem to link to the quest item object in the scene
  9. In the character’s Update function, check to see if the quest item was collected
  10. If it was collected, we want to destroy it
  11. And we only want to run this check until it has been found, otherwise this check will throw an error after the object is destroyed
  12. Be sure to link the Quest Item to the public slot on the character’s script
  13. At this point if you test, the Quest Item should disappear when you collide with it
  14. We should also add a public bool in the character’s script to activate the quest after the player talks to her
  15. Activate the quest when the player talks to her
  16. In the QuestItem script, we need a public reference to the character’s script (in this case I left it called Enemy.cs from the previous tutorial, even though it is now used as an NPC)
  17. Before collecting the item, check if the questGiver’s quest is active
  18. Remember to link the character to the QuestGiver slot in the scene
  19. Now the cat can only be collected after the quest has been activated by talking to the granny
Completing the Quest
  1. We need to add a new section to the talking portion of the character’s script to change the text if the Quest Item was found
  2. Now to reward the player for completing the quest. Create a new Text object to show the reward, in this case I’m going to give the player XP
  3. We want this text to be large, bright, and eye-catching
  4. Let’s create an Animation to make the text popup more exciting
  5. Attache the new animation to the Text Object
  6. Open the Animation window
  7. Make sure you have the text selected, then Add Property for the Text.Color and Anchored Position
  8. Give it an Alpha of 0 for the start and end keyframe, and Alpha of 1 for a keyframe in the middle, so it fades in and out
  9. Set the Y value higher in the last keyframe so the test floats upward
  10. Now we need to trigger the animation. In the Animator window, create an Empty State
  11. Set that as the Layer Default State
  12. Make a transition to and from the Popup animation
  13. Make a new Trigger in the Parameters tab and use that as the Condition to transition to the Popup animation
  14. Remember to uncheck the box for Has Exit Time
  15. Back in the character’s script, add a new public Animator to reference the popup text in the scene
  16. In the quest completion part of the script, trigger the animation
  17. Remember to drag the text into the public slot you created
  18. Set the starting Alpha for the text to 0 so it is not visible from the beginning
Summary
You should now have a quest giver that requests a specific item, the ability to go and collect that item, and a reward when you return to the quest giver. This can easily be expanded for a quest giver to ask for a certain number of things like “collect 50 gems” or “kill 10 enemies”

Sunday, March 25, 2018

Game Dev Tutorials

Many game devs get their start from following tutorials, because even though there has been a surge of game-related classes and programs in colleges and schools, a lot of the content taught is overarching principles of design and workflows. Hands-on how-to material is still largely dominated by online tutorials.

Tutorials are a great way to learn how to build specific mechanics within specific engines or frameworks, and can be beneficial even for seasoned developers. Often tutorials cover not only scripting, but also art asset creation, world building, animation, and effects...you can make a complete game from scratch by following a tutorial, or you can pick up bits and pieces to fill in knowledge games.

For the past year I've been working on tutorializing content that I teach in classes, workshops, and camps. This is beneficial to anyone participating in my classes because it means they can work at their own pace and continue to learn even when I am not there, and it also allows people from all around the world to experience this content because it is available online (and much of it is free).

If you are an aspiring game developer, or if you teach game dev classes or workshops, I hope you will consider checking out my suite of tutorials. Here is a rundown of what I have to offer (all tutorials use the Unity game engine):


 

This tutorial covers everything you need to know about using 2D sprites in Unity, either for 2D game objects  animated for 2D gameplay, or for UI elements in a 2D or 3D game. Topics covered include sprite sheets, color, sliders, and rotation/scale/position animations.



Unity has a built-in physics engine that allows you to quickly and easily animate objects using physical properties such as force, torque, friction, mass, and bounciness. In this tutorial you will learn how to use these different properties to create a wide range of movement and behavior for physics-based objects in both 3D and 2D.



In addition to rigidbody physics, Unity also supports cloth physics. This tutorial covers the basics for setting up an object to behave like cloth, including constraints, stiffness, stretchiness, and animated force for wind and gravity.




This tutorial breaks down the most common features of Unity's Particle System component, including sprite sheets, velocity over lifetime, color over lifetime, trails, emissions, and bursts.



One of the biggest distinguishing factors from a student game and a professionally developed game is the "juiciness" of the interactions. The hallmark of game design is making the game "feel good" and so much of that good feeling comes from making things feel reactive to the player's actions. This tutorial covers specifically using particles and sound effects to make the interactions juicy.



This tutorial is available on Pluralsight and covers the full pipeline for creating your first game prototype. It covers whiteboxing, importing assets, building a level, adding animations, particles, lighting, and sounds, and making it a complete experience with a UI start screen and win/lose screens.


https://www.pluralsight.com/courses/unity-vr-fundamentals

This tutorial is specifically intended for aspiring VR developers, and gives the basics of getting started with room-scale VR on the Vive, and mobile VR.

Please subscribe to our youtube channel for more tutorials, gameplay videos, and other fun things! Thanks for reading!