Sprite sheets and animation clips are already set up for you in Assets/ArtAssets/player
.
Player
entity and add the Player
scriptPlayer
for itrun_right
clip into the animator pane and set it as the default stateTest - you should see the player character running in place with the animation you added.
In the animator pane
DirectionX
and DirectionY
and a boolean parameter IsMoving
Open the Idle state and click on the blend tree inside. Edit it in the inspector:
2D Freeform Directional
DirectionX
and DirectionY
Do the same to create a Run
state with the four run animation clips.
Connect the transitions in the animator pane
Idle
state the defaultrun_right
stateIdle
and Run
Click on the transition arrows to edit their properties in the inspector:
Has Exit Time
Transition Duration (s)
to 0.1SetFloat("varname", value)
and SetBool("varname", value)
to update the animator based on movementTest - the player character should now run in the correct direction.
Implement a melee attack system where the character can perform slash attacks that follow the mouse cursor direction.
SlashRoot
and Slash
under Player
Slash
to the SlashRoot
Slash
and use the slash image in ArtAssets
Slash
and double-click to open the animation paneSlashRoot
into the animation pane to target it and add the position and scale propertiesSlash
animation controller and test it.Idle
state and transitions to the slashAttack
that triggers the transition Idle -> Slash with transition duration 0Has Exit Time
(play the whole clip) and transition duration 0.1Player
script, get a reference to the slash animator (use Transform.Find to get children by name)SetTrigger("varname", value)
on the slash animator when the user clicksSlash
state in the animation controller and add a behavior, the provided SlashAttackBehavior
scriptPlayer
to let it know the attack has finishedSlashRoot
so that it only appears during the attack actionUpdate the player hierarchy like this, where the ActionPivot is at the character chest and the ActionAnchor starts out to the right:
In your player script Update, get a vector pointing towards the mouse and use it to rotate the action pivot. To calculate the angle corresponding to a vector and rotate a transform by that amount, use these formulas:
float angle = Mathf.Atan2(mouseDirection.y, mouseDirection.x) * Mathf.Rad2Deg; actionPivot.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
Update your code so that the animator direction (character facing) follows the mouse rather than WASD.
Test the system to ensure the character faces the mouse cursor and the slash attack appears in the correct direction when left-clicking.
Build a target dummy that responds to player attacks with a health system and visual feedback when taking damage.
Create the FlashRed method below and call it from TakeDamage. This is using a C# coroutine
which is a form of single-threaded asynchronous code (like async/await
in JavaScript and yield
in Python). The coroutine runs until it hits a yield
statement, then releases control and waits there until the processing thread is
available. Every time the thread comes back, it checks the provided condition (in this case that a certain time has passed) and if so it continues execution.
This has the effect of running the coroutine over some number of frames:
flashDuration
seconds later: turns it back to the original color, then yieldsflashDuration
seconds later: goes back to the top of the loop, turns the sprite color red, then yieldsflashDuration
seconds later: turns it back to the original color, then yieldsflashDuration
seconds later: goes back to the top of the loop, exits, and finishesTest the system by attacking the dummy and observing both the health reduction and the color flash effect.
Create a visual health bar system for the target dummy that dynamically updates to show the remaining health as a percentage.
Center
button to Pivot
Attach the HealthBar to the player and call SetPctHealth from the Target script on TakeDamage. Test your code to see that when you hit the dummy the health bar updates.
Fix this place up. The generic blue background is so out of style.
In the Hierarchy, right-click and select 2D Object > Tilemap > Rectangular to create a new Tilemap GameObject. This automatically creates both a Tilemap and TilemapRenderer component on a GameObject called "Grid".
Select the Tilemap and click the New Palette button that appears on the lower right corner. (Or Window > 2D > Tile Palette). In the Tile Palette window, click "Create New Palette" and save it in ArtAssets. Drag the sprites from mystic woods / palette into the new palette.
Select the Tilemap GameObject in the Hierarchy. In the Tile Palette window, select the Brush tool and choose tiles from your palette. Click and drag in the Scene view to "paint" tiles onto the tilemap, creating your arena background.
Use different tiles to create variety in your background - floor tiles, wall tiles, decorative elements, etc. You can use the Rectangle tool in the Tile Palette for quickly filling large areas, and the individual brush for detailed work.
Test your tilemap by playing the scene and ensuring the background appears correctly. Adjust the Tilemap's sorting layer if needed to ensure it renders behind your player and other game objects.
Implement a fireball magic system that allows the player to cast fireballs by right-clicking, complete with spellcasting animation and projectile mechanics.
controls.UI.RightClick.performed
)Test the complete fireball system by right-clicking to cast fireballs at the target dummy and verify that damage is applied correctly.
Add the additional 4.6 checklist items to your git commit message!
Have the fireball apply a burn that does a small amount of damage every second for 3 seconds. Implement the burn status in the Target script and trigger it instead of TakeDamage. You could also display a small fire icon over the target dummy while it is burning.
Add the additional 4.7 checklist item to your git commit message!