2D Top Down игра на Unity с нуля #5 | Анимация главного героя
Summary
TLDRThis tutorial demonstrates how to create a 2D character in Unity with animations for idle and running states. It covers setting up a camera, organizing game objects, and importing and configuring sprite animations. The video also delves into creating an animation controller, adding transition logic between states, and using a player movement script to control animation triggers. Additionally, the character is programmed to face the mouse cursor dynamically. This comprehensive guide walks through each step of the process, providing clear instructions for implementing smooth character movement and animation in Unity.
Takeaways
- 😀 The video focuses on creating a 2D game with a character that features animations for idle, running, and turning based on the mouse position.
- 😀 The importance of separating the logical and visual components of the game is highlighted to make it easier to develop and maintain.
- 😀 A sprite animation preset is created for consistent settings across imported sprites, ensuring ease of use in future imports.
- 😀 The sprite sheet for running animation is sliced into multiple frames to create a running animation with 8 frames in one row.
- 😀 An Animator Controller is set up with two animations: idle and running, to control transitions based on the player's actions.
- 😀 To transition between idle and running animations, a boolean parameter is used in the Animator Controller to check whether the character is running or idle.
- 😀 The transition between animations includes removing the transition time for instant switching between idle and running.
- 😀 Each animation has a loop time property enabled to ensure the idle and running animations continue playing when the character is in their respective states.
- 😀 A custom script for the Player Visual component is created to manage the animation transitions and character movement based on input.
- 😀 To make the character face the mouse direction, the player's sprite is rotated based on the mouse's position relative to the character's screen position.
Q & A
What is the purpose of separating the visual and logical parts of the player object?
-The visual and logical parts of the player are separated to make the game easier to maintain and develop. The visual part handles how the player appears on screen, while the logical part focuses on interactions with the environment. This separation allows for better organization and flexibility in the game's development.
Why is a 'Pixel preset' created in the script?
-The 'Pixel preset' is created to automate the process of applying the same settings to all imported sprites, such as pixel size and MIP settings. This saves time and ensures consistency in sprite handling throughout the game.
How are sprite animations handled in the game?
-Sprite animations are managed by creating an Animation Controller and assigning it to the Player Visual object. Different animations, like idle and running, are set up with transitions triggered by conditions like whether the player is moving or not.
What is the significance of setting 'Loop Time' for animations?
-'Loop Time' ensures that the animation will continuously repeat. This is important for animations like 'idle' and 'running,' where the player character should remain in a constant animation loop while idle or moving.
What is the role of the 'Animator' component in the game?
-The Animator component controls the playback of animations for the player. It uses parameters such as 'isRunning' to determine which animation to play, such as switching from idle to running based on player movement.
How does the game determine if the player is running or idle?
-The game checks the player's movement input. If the X or Y values of the input vector are non-zero, the player is considered to be running. Otherwise, the player is idle.
What is the purpose of using a Singleton pattern for the Player class?
-The Singleton pattern ensures there is only one instance of the Player class in the game. This is useful because there should only be one player object, and it allows for easy access to the player's properties and methods throughout the game.
Why is the Flip X property used for rotating the sprite?
-The Flip X property is used to rotate the player sprite based on the position of the mouse. If the mouse is on the left side of the player, the sprite is flipped horizontally to face the mouse. This creates the illusion of the player turning towards the mouse.
How does the game handle mouse position for sprite rotation?
-The game compares the mouse position with the player's screen position. If the mouse is to the left of the player, the sprite's Flip X property is set to true, flipping the sprite. If the mouse is to the right, the sprite remains in its default orientation.
What improvements were suggested for the running animation speed?
-The running animation speed was adjusted by setting the frames per second (FPS) value. Initially, the animation was too fast, so the FPS was reduced to 12 frames per second for a smoother animation.
Outlines
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowMindmap
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowKeywords
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowHighlights
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowTranscripts
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowBrowse More Related Video
TOP DOWN MOVEMENT in Unity!
Player Movement & Animation | 2D Platformer Game Tutorial with Construct 3 #1
How To Make a Topdown RPG in Godot 4: Adding The Player (Part 1)
Roblox Studio - 8 Direction Movement System - Scripting Tutorial
SIMPLE 3rd Person Character Controller Godot 4 Tutorial
*NEW* How to Use Motion Matching in Unreal Engine 5.4
5.0 / 5 (0 votes)