Unity game development essentials
This project is a testing prototype that I have used to test various mechanics, unity features, data types, etc. Some I test I already knew (e.g. player moves forward and back rotate), others I learned (e.g., loading from “resources” and activating other game objects animators from code respectfully). The goal of the project is to test out unfamiliar essentials to improve my C# programming and general unity engine knowledge. I created this little level with 3d tool kits modular prefabs and particles as a start to testing.
WHAT I AM DEMONSTRATING:
• Player movement and its abilities to shrink and regrow, change color, and shoot randomized size lava balls.
• Raycast mechanics such as spawning rocks, moving the player cube, changing rock colors and detecting certain objects like “items”.
• Each Trigger has a distinctive behavior that will respond when the player enters their trigger such as camera triggers, light trigger, animation trigger, etc.
• Speaking of camera triggers, each camera trigger can be triggered by the player to be idle, follow, move or both (except idle).
• Creating a mesh from code using a certain number of UVs, vertices’, tri’s, etc.
• Loading objects from resources without getting a public reference to the game object.
• Creating an object by code.
• Appling gravity to a game object that they are stuck on a sphere as if they were on a planet like Earth.
• Minimap follows and rotates with the player, also can be expanded fullscreen.
• Particle activates on certain game objects if the player collides with that object.
WHAT I LEARNED:
--Player Mechanics--
• Changing player cube size with transform.local scale by inputs.
• When instantiating lava balls, changing the game object’s name to “sphere” instead of “sphere clone” and create a random range of Vector 3.one size scales: meaning it will spawn each of random sizes.
• Making Lava balls use force mode acceleration to ignore their mass, so it doesn’t slow down or speed up depending on the mass.
• 2 ways to write Vector3.one.
• Changing player cubes colour by <Render> material.color by inputs.
• Able to instantiate dust particles with a certain wall from the player cubes rotation/angle with the quaternion.Identity with its transform. Position.
--Camera manager and Triggers—
• Made two separate scripts that can smoothly follow or look at at the player depending on which camera trigger the player enters. This is done with Vector3s, look at, quaternions, lerp, and slerp depending on either script. It can offset the camera if need too.
• Using Camera triggers to store a reference to the Camera Managers camera states to control which state of the 4 to execute specific code. Depending on the selected public state when the player cube enters the trigger, the camera will switch states ( more info next sentence).
• Creating a camera Manager that controls the current Camera behavior states such as Idle, follow, look at, or both follow and look at by using switch states with functions.
• Creating a minimap for the first time ever by adding a second camera above the player and rendering a certain distance below. The minimap can follow the player cube by moving and rotating with a vector 3 and Quaternion. Eular respectfully.
• Making the minimap expand fullscreen by pressing a button M and shrinking to its default size once M is pressed again using the Camera rect.
• Activating another game objects the animator to play a specific animation bool when the player’s cube enters a trigger referencing that Animator. Also playing a different animation if the player's cube leaves the animator trigger.
• After entering a door Trigger, use a lean tween animation to smoothly open the door downwards for only 2 seconds. Lean tween also bypasses complex datatypes like Lerps.
--Raycasting and Mouse events--
• Raycasting from a camera onto the collider (ground) to get the player cube to move to a new position wherever the player has clicked on while still making sure it's on the same y.position while moving.
• Using the rigid body’s method of movePosition that allows the player cube to move into a new position once the player has clicked on that position.
• Making the player cube follow the mouse cursor to move to a new position on the ground by aiming it from the camera (cam,ScreenPointToRay(inputPosition)), basically by player's cursor.
• How raycasts store info on what they hit.
• How certain game objects can be detected by the raycast when checking its name by hit.collider.name. Also scaling it with transform.Localscale by the same raycast.
• Using an Array of what and storing the data of what the raycast hits based on its game object name in the console and turning certain game objects green if they have a renderer on their parent game object.
• How to spawn rocks from the camera raycast when the mouse is clicked on a collider.
• How Mouse events are not based on cursor design but only on what information the mouse touches or hovers over.
• The difference between OnMouse Enter, Exit, and Down and a few others like drag and over.
--Other Mechanics and misc--
• Lerps and slerps are good for moving game objects without a rigid body.
• The Resources datatype can find game objects in a Resources folder by a Resources.load code and load them into the scene without using a public game object reference.
• Resources.FindObjectsOfTypeAll can be used to locate assets and scene objects.
• Turning the Player cube's gravity off and some constraints when their position is on a sphere (like a planet).
• How Fixed update is good for rigid bodies- particularly for movement.
• How the player's gravity’s attractor can attract on the sphere it updates its movement regardless of moving or not so it does not fall off the sphere.
-Creating Mesh and objects--
• Creating mesh by code by first adding components of Mesh filter, Mesh Renderer, and clearing the mesh empty. Then adding vertices, UV’s, and Triangles by using arrays with Vector 3,s Vector 2s, and ints all by code.
• Creating Quads by code by determining array vertices of vector 3s of quad height and quad weights, tri’s by array ints to set on the quad, normal’s by array vector3’s, UV’s by Vector2’s and then assigning them to the quad.
• Getting the created quad to move back and forth by using a While loop to move its vertices and normals by multiplying with Mathf.Sin (Time. time).
• Creating a new game object by code by first giving it a name, and mesh type such as a sphere, assigning it to a position, then adding rigidbody. All without assigning it in Inspector before pressing play.
WHAT COULD I DO BETTER?
• creating mesh by code was very complicated, if there is a time when I need to use those mechanics again for my future games, I may need to do some more research on how to make all sorts of unique mesh like the default Unity 3D primitives.
• The raycast checker on the player cube detected camera triggers, making it difficult to detect the “item” by raycast, I will need to find out other ways camera triggers can detect the player without getting in the way of the raycast.
• When the dust particle appears from the cube wall collision, it should play in the same rotation position as the cube instead of just one rotation.
• At the moment I could not get the dust particles to instantiate in the right rotation when colliding with certain walls, next time I will need to find out how to make them do so consistently.
OVERALL:
It was an interesting exercise. I got a better understanding of Unity, datatypes, and making mechanics. This will make my game dev journey much easier since I understand the code a lot better. Hopefully, I can do something like this again to know more advanced and expert essentials.
#pc #GameDesigner #MechanicTest #Unity3D #gamedevelopment #gamedev #UnityEngine #IndieGames #AustralianGameDevoloper #indiedev #indiegame #indie #indiedev #Gamedev #IndieGames #SoleDevoloper #indiegaming #IndieGameDev #indiegames
Kommentarer