To kickoff with my engine work once more I added a player wellness bar. This uses the same logic every bit all other health bars, only is assigned with a reference to the behave (to access the health organisation) instead of getting the reference automatically.
|
| The bar is the aforementioned sprite as what floats above the enemies heads, attached equally a child of the camera instead of being a UI element. This is considering it will be easier to hibernate backside menus and such, while still remaining with the same logic. |
|
| I added a few additional lines of code, and so I could toggle whether the bar would be grabbed automatically (if it is a child of the object) or if I want to assign it manually (if information technology isn't a child of the object) |
|
| This is how it looks from the player's perspective |
|
| Side by side, to add my contrivance mechanic, I needed to change my character controller. The alterations add a "canMove" variable, and if this is true so the bear model wont react to player inputs or mouse motion. I besides added a new primal bind, where if the histrion presses left shift it will showtime a coroutine called Contrivance(). I besides added a "Lerp" to the players looking around. This means they wont immediately snap to the cursor, and instead whatsoever movement is applied over 0.five seconds. This doesn't take much effect on normal looking effectually, but it means when the player's cursor passes over the bear, information technology wont snap to the cursor (instead, actually turning around), which looked weird. |
|
| This is the dodge coroutine. It prevents the player from colliding with enemies, moves them forwards, and prevents them from moving or turning for 0.2~ seconds, then allows them to motion again, while providing a 1 second delay until they tin can dodge over again. |
|
| However, in my experimenting with the code for the contrivance, I attempted to make the bear roll while dodging. Naturally, this didn't piece of work, and then I adjusted this into a hidden mechanic, which makes the bear do a backflip. It also plays a flame effect behind the bear. This is spring the B key (for backflip). Information technology has no gameplay use, except looking really cool. |
|
| I besides added two new options for items in the "stat upgrades" switch argument. Ane which restores health, the other which restores "cooldown" (which volition exist an alternative to an ammo system) that I haven't implemented nonetheless. |
|
| Back in blender, I rigged my model using the rigify extension. I and then parented the model to this rig using automatic weights. |
|
| I altered these weights manually and then that the movement of the legs wouldn't milkshake the bear'southward tum as much, and so that the bear'southward ears would move with it's caput. |
|
| I then created 5 animations by altering the position and rotation of the basic in the rig, and applying each change as a keyframe. Blender then automatically blends between the keyframes. The idle animation is the bear bobbing up and downwardly slightly, his head moving more than the rest to make information technology appear like he's breathing in and out. The melee assail animation but affects his forepart left leg and mitt, which comes out to the side, then crosses his torso before returning to the ground. Information technology looks more like a slap than a hook swipe. The scroll blitheness makes the carry roll up for three frames, before rotating 360 degrees across viii frames. He begins to uncurl on frame 7 and finishes on frame 10. The walk forward animation is the conduct moving forwards. He moves subtly upward and down while walking. I play this in contrary for walking backwards. The walk left animation is cocky explanatory too, his rotation and position change along with how his torso weight would shift. I play this in reverse for walking correct. |
|
| I then import these animations equally part of a blend tree. |
|
The blend tree takes the parameters of x and y, being the left and right movement and up and down movement of the bear relative to it's own rotation. I then assign these to each edge and double their speed, inverting the backwards move. I actually accidentally made the "walk left" a walk right motion, then I capsize the leftward walking. |
|
Here is the blend tree when continued to the balance of the deport's animations. The roll can transition from any country, but the role player has be to walking or idle to set on, and therefore cant attack during a whorl. |
|
These are the transitions for exiting the melee set on (left) and entering the melee attack (right). The attack blitheness tin interrupt whatsoever of the motion animations at whatever time, however move cannot interrupt the assail animation. The aforementioned is practical to the ringlet animation, but this tin can transition from whatever state. |
|
Next I added blitheness events to the player's melee attack animation on frame two and frame 10. |
|
| They trigger this line of lawmaking, which gets the current country of the player'south set on collider and inverts it, essentially acting as a toggle. |
The only other basic move I haven't added for the player is shooting their currently equipped gun. To add this logic, I planned to use code from unity's FPS Microgame demo, only the code was much to complex for my needs, then I instead programmed information technology myself.
|
| This is my fully modular system for creating guns. Information technology has the option for semi auto, burst fire and auto guns, bullet spread, time between shots... |
|
| Raycast upon shooting to bargain harm, a bullet tracer which follows the path of that raycast, and a muzzle wink. For shooting, it spawns a raycast, checks what the raycast hit and deals damage to enemies in that raycast. The bullet tracer is just a trail renderer that travels to the point of impact after the raycast has fired, and so gets destroyed when it arrives. For reloading, a timer is counting downward until the role player has waited a certain number of seconds since they last fired their weapon. Afterwards this time, the gun has i bullet restored every unmarried fourth dimension that "reloadTime" amount of seconds has passed. once information technology reaches the full magazine size of the gun, information technology stops calculation more bullets. |
|
These are the stats for my pistol. Allow Button Hold is imitation, making it semi-automated, and bullets per tap is only i. The damage value will change when I balance the game. |
|
| This is the logic for picking upward weapons. Instead of swapping the weapons out, the carry actually has all weapons attached to it's gun slot, merely inactive. This finds the player's gun slot and sets the electric current weapon to be inactive. Information technology drops that weapon'south prefab where the item y'all just picked up is, then swaps the current active item to the one you just grabbed and sets that to exist active. It so stores the prefab of the object you but touched as a static variable, and loads the object'southward icon into the weapon UI slot. |
|
| This is the logic for picking up active items. It drops whatever you're currently belongings, then sets the current active particular to be the "projectile" version of any the active detail you just picked upward is. It sets the electric current object'due south prefab as a static variable, and and then loads the object'south icon into the active item UI slot. |
|
| This is the logic for dropping items. Information technology spawns the item prefab stored at the position of the previous object. To preclude the player instantly picking it back up, it disables the collider. This then gets gear up active 1 second after by the particular itself. |
|
| Hither is a diagram showing and labelling all the current UI elements. The icons are temporary icons pulled from google images just to demonstrate the idea. I plan to accept an overlay on your active detail to prove the cooldown and maybe motion it to next to the health bar. |
|
I immediately overhauled this UI with a new i that includes a minimap. The minimap volition shows icons for the shop and the boss rooms, along with the doors between rooms. |
|
| To add this, I added new objects to my room prefabs, being a MapUI, which is just a sprite of a rectangle with rounded corners, and a "Door" to each genpoint, which is a sprite of a rectangle with the aforementioned colour as the MapUI rectangle. While making this, I had an event with the door sprites withal spawning when a room was blocked off. |
|
| To accept this appear on screen (and follow the thespian between rooms) I added a new photographic camera called MapCam and set information technology to exist orthographic, and then that it doesn't render depth. I then change information technology's culling mask to just a new layer named "Map Simply". This means information technology will only render objects on the MapOnly layer, and nothing else. I as well changed it's background blazon from skybox to solid colour, and set this to be transparent. I attach this every bit a child of my main camera, and finally, I send the output of the camera to a render texture. |
|
| This is the return texture I'm sending the camera's output to. A render texture takes a photographic camera'due south output and converts information technology into a texture. I accept this texture to update in real time, and exit most of the other settings on default. The resolution is set to 300x300 considering that's the size of the minimap'south UI box in game. |
|
| I then set the return texture I but created to a unity UI Raw Epitome component, and position this on my UI accordingly. Nonetheless as you can encounter there are some door sprites leading to an empty room. |
|
| To set up information technology, I added this line of code, which deletes the door sprite fastened to whatsoever genpoints that collide with each other. |
Adjacent POST
Publicar un comentario for "Unity Lerp Stops Moving When Object Is Move Again Before It Stopps"