Posts

Showing posts from May, 2021

Accessing Variables in Other Scripts in Unity

May 26, 2021 Accessing Variables Unity Title: How To Access Variables From Another Script In Unity By: Infallible Code Youtube - Tutorial #1 Description: Goes over many programming techniques within Unity to access variables in one script from another. Key Concepts Scripts C# classes that inherit from MonoBehaviour. Collaborators Scripts that require a reference to at least one other script in order to function. Dependencies Objects that collaborators need in order to function. Categories of Resolution Where the burden of dependency resolution lies. External Resolution The responsibility of dependency resolution falls somewhere else. Public Properties Expose dependency of a public field or property Simple and requires no overhead, but can easily make bugs that are also hard to debug. This is because it can be unclear where the dependencies lie. Editor Properties Expose serializable dependencies in the Unity editor. Use SerializeField

Singletons in Unity and Many of Their Downfalls by Infallible Code

May 26, 2021 Singletons Unity Title: Everything You Need to Know About Singletons in Unity By: Infallible Code Youtube - Tutorial #1 Description: Goes over the true properties of singletons in code and why they should be used sparingly in Unity game development. Intro to Singletons Singleton Pattern: class that is both globally accessible and can only be instantiated once Common Example: Audio Manager - because it is something many scripts will want access to, and you specifically want only one in your game at a time Singleton Requirement #1: Global Access Specification Singletons sound promising because they are an easy solution to "how do you access other scripts" or "how do you fill your class dependencies". Using Singletons for access can hide the fact that a class depends on another, which can lead to difficult to track bugs and difficulties. This may lead to using the singleton even more than necessary because of ease of ac

Game Project: Flying Game - Part 3 - Camera Controller and Zoom Control

May 25, 2021 Flying Game Camera Controller Overview After getting the basics of the camera controller down, I wanted to explore ways to make it feel more immersive. One of the ways I've seen racing or other fast moving games handle this was to have a zoom that mimicked the acceleration to make that feel all the more impactful. Following this, I wanted to look into connecting the player's speed with the amount the camera zooms in on the player. Setting the Camera Zoom Suggested by Player Speed Since the game has a speed boost option, I wanted the impact of the speed boost to be larger than any normal speed the player can reach. With this in mind, I was looking at an approach where normally their max speed gets the camera up to around 80% of the maximum zoom, and activating a boost is the only way to hit the 100% zoom mark (creating a significant difference in zoom specifically when boosting). One immediate issue with this approach is that any zoom that is di

Coroutine Fundamentals in Unity

May 20, 2021 Coroutines Unity Title: Introduction to Game Development (E21: coroutines) By: Sebastian Lague Youtube - Tutorial #1 Description: Covers the basics of coroutines in Unity. Title: Coroutines In Unity - What Are Coroutines And How To Use Them - Coroutines Unity Tutorial By: Awesome Tuts Youtube - Tutorial #2 Description: Covers some intermediate complexity uses of coroutines as well as tying them in with Invoke calls. Title: Coroutines - Unity Official Tutorials By: Unity Youtube - Tutorial #3 Description: Old official Unity tutorial on the fundamentals of coroutines in their system. Overview Coroutines appear to be a strong tool within Unity that I still am looking for ways to implement better in my systems. While understanding the basic uses for them with timing related events, I feel like they offer a lot more that I am not utilizing, so I wanted to further my understanding of them by following up on one of

Lerp Fundamentals in Unity

May 10, 2021 Lerp Unity Title: How to Use Lerp (Unity Tutorial) By: Ketra Games Youtube - Tutorial Description: A brief coverage of exactly how Lerp works in Unity with a couple ways to use it. Overview I was recently researching ways to effectively use Lerp in Unity and came across some strange implementations that made me unsure if I understood how it worked. This video however specifically covered that case and explained that it does work, but it's not a particularly ideal solution. The case covered is specifically called the "Incorrect Usage" in this video. It is when Time.deltaTime alone is entered as the time parameter for Lerp. As I thought, this is just entering some tiny number as a time parameter each time it is called, which is then used to just some value between the intial and final values entered into the Lerp. It is not very controlled, and it leads to a strange situation where it keeps getting called and updated but it doe

Game Project: Flying Game - Part 2 - 3D UI Guide with Rotational Matrices

May 4, 2021 Flying Game UI & Matrix Rotations Overview I wanted to make a 3D UI element which could direct the player in open flying space towards a point of interest or goal. This needed to point towards the object positionally, as well as account for the rotation or direction the player is facing. This makes sure that no matter where they are and what direction they are facing, it can guide them to turn the proper direction and make informed decisions to move directly towards that goal. After deciding that changing my frame of reference could be a solution for this problem, I found Unity's InverseTransformDirection method which can change a Vector from one space to another. To make sure this was providing a result similar to what I expected mathematically, I also wrote out the math for performing a matrix rotation on the vector and was happy to see it gave the same results. 3D UI Element - Real Time Guide Towards Goal Add a 3D Element to the Unity Canvas