2D Animation Offset in Unity
Updated: Jul 25, 2020
The clip offset only shows up if the animation is animating the root transform. It is meant to offset the animation position, and doesn't apply otherwise. Instead, you can create an override track and keyframe the position/rotation you want.
Unity has a powerful animation editor. The concept is that you attach an Animator component to a Game Object and then attach an Animator Controller to the Animator. An Animator Controller allows you to arrange and maintain a set of Animation Clips and associated Animation Transitions for a character or object. An Animation Clip lets you define animations to Game Object properties along a timeline of keyframes.
This video tutorial by Erwin Broekhuis explains the simple fix, which is to wrap the animated object in a parent object and attach the Animator to the parent instead. However, the video is using the Animation component which has been deprecated in favor of the newer Animator component.
Step 1: Create the Parent Object
Create an empty object off the root of the hierarchy. You can name the parent whatever you like, here it is called Parent.
Step 2: Add the Child Object
Add the child object under the parent. In this walkthrough, we are simply adding a Cube 3D object. The child object should default to transform.position (0, 0, 0), which is a local coordinate position relative to the parent. You can name the child whatever you like, here it is called Cube.
Step 3: Add the Animator Component to the Parent
Add an Animator component to the parent object. The Animator component is found in the miscellaneous category.
Step 4: Create an Animator Controller
We need to create an Animator Controller to manage the animation clips and state transitions. I suggest creating a folder named Animation to store your animation controller and animation clips. In the Project window, right-click on the Animation folder and choose Create > Animator Controller. You can name the controller whatever you like. Here it is called CubeAnimatorController.
Step 5: Attach the Animator Controller to Animator
Attach the Animator Controller to the Animator by dragging it onto the Controller property of the Animator. To do this, start by selecting the Parent object in the hierarchy then click on the Animation folder in the Project window. Drag CubeAnimatorController from the Animation folder onto the empty Controller box under Animator in the Inspector window.
Step 6: Create an Animation Clip
If it’s not open already, open the Animation window by choosing Window > Animation from the Unity Editor menu. You can place the Animation window anywhere you like. Personally, I like to position the Animation window in the same group as my Project window in such a way that the Scene window is visible at the same time as the Animation window.
Select the Cube object in the Hierarchy window. Click on the Animation tab so that the Animation window is visible. You should be prompted to create an animation clip.
When you press the button to create an animation clip a dialog will open prompting for the location to save the animation clip. I suggest saving it in your Animation folder where you saved the Animator Controller. Name the animation Clip CubeMove.
Note that creating the animation clip also adds a corresponding state for it to the CubeAnimatorController you attached to the Animator. This blog post does not cover anything related to the Animator Controller or state transitions.
Step 7: Add the Cube’s Transform.Position Property to the Animation Clip
In the Animation window, with the CubeMove clip (state) selected, click the Add Property button. Do not select the root Transform object but instead expand Cube and choose Cube > Tranform > Position.
At this point, you will see the Cube Position property in the Animation window with two keyframes added to the timeline, one at 0:00 and one at 1:00. These times refer to the frame number. By default an animation has 60 samples and will last 1 second at 60 frames per second.
Step 8: Add a Keyframe to the Animation
Click on the timeline at position 0:30 then click the button in the Animation window to add a keyframe. You will notice that the Animation editor will enter “record” mode with a few visual cues:
The record button will be depressed
The game Play/Pause buttons at the top of the Unity Editor will be colored red
The Transform.Position property attributes in the Inspector for the Cube will be colored red
Change one of the Transform.Position property attributes. For example, change X from 0 to 2.
Note: At this point you may see that both the Parent and the Cube objects are selected in the Hierarchy window and that a Transform.Position will be added to the animation clip for both of them. If this happens, right click the Parent Transform.Position and choose to remove the properties from the animation. This is key to ensuring that the animation remains relative to the parent object’s current position.
Click the Record button in the Animation window to stop recording.
Step 9: Test the Animation
Press the Play button in the Animation window to test your animation. You should see your Cube sliding 2 units along the X axis from its start position then return back.
Step 10: Move the Parent Object and Repeat Test
To confirm that the relative position animation works as expected, move the Parent object somewhere else in the scene then click the Play button in the Animation window again. If everything is configured correctly, the animation should begin from the new location of Parent and animate 2 units along the X axis and back. It should not jump to the location where the animation was originally recorded.
15 - Introduction to Animation Parameters in Unity
Animation Parameters are variables that are defined within an Animator Controller that can be accessed and assigned values from scripts. This is how a script can control or affect the flow of the state machine.
For example, the value of a parameter can be updated by an animation curve and then accessed from a script so that, say, the pitch of a sound effect can be varied as if it were a piece of animation. Likewise, a script can set parameter values to be picked up by Mecanim. For example, a script can set a parameter to control a Blend Tree.
Default parameter values can be set up using the Parameters section of the Animator window, selectable in the top right corner of the Animator window. They can be of four basic types:
Integer - a whole number
Float - a number with a fractional part
Bool - true or false value (represented by a checkbox)
Trigger - a boolean parameter that is reset by the controller when consumed by a transition (represented by a circle button)
Parameters can be assigned values from a script using functions in the Animator class: SetFloat, SetInteger, SetBool, SetTrigger and ResetTrigger.
Setting Up Characters with Animations in Unity with the Animator Controller
ANIMATE 2D CHARACTERS in Unity
At the very core of animation is an illusion. The “Illusion of Life” is what it is called. We think an animation looks the best when it produces a greater illusion of a living character. This makes sense, does it not? When we see an animation of a living character, it triggers a memory or recognition of a live being we have seen in real life. Therefore, the task of the animator is to closely follow the rules of movement that we see in the real world because that will greatly increase the illusion that what you are seeing is a real being, moving and functioning. And this is the goal of this tutorial. We are going to start creating this “Illusion of Life” for a 2D character.
HOW TO MAKE 2D GAME ANIMATIONS IN UNITY
Unity Simple Animation States for 2D Walking
How to Rig and Animate a 2D Character in Unity
How to quickly rig and animate a 2D character in Unity with the 2D Animation package and tools. The following package versions are only supported for the following Unity versions:
· 2D Animation package version 5.x.x - Unity 2020.2 or later
· 2D Animation package version 4.x.x - Unity 2020.1
· 2D Animation package version 3.x.x - Unity 2019.3
2D Animation and PSD Importer integration
You can use the 2D Animation package with the PSD Importer package to easily import your character artwork from Photoshop into Unity for animation. The PSD Importer is an Asset importer that supports the import of Adobe Photoshop .psb files into Unity and generating a Prefab made of Sprites based on the source file and its layers (see Adobe’s documentation on Layer basics).
The .psb file format has identical functions as the more common Adobe .psd format, with additional support for much larger image sizes. See the PSD Importer package documentation for more information about the importer’s features
Adobe Photoshop PSB format
For character animation with the 2D Animation package, the PSD Importer package is required. The PSD Importer package currently only imports the Adobe Photoshop .psb format, and does not import the Adobe .psd format. The .psb format has identical functions as .psd, and is able to support larger image sizes.
Optional Performance Boost
You can improve the performance of the animated Sprite’s deformation at runtime by installing the Burst and Collections package from the Package Manager. This allows the 2D Animation package to use Burst compilation to speed up Unity’s processing of Sprite mesh deformation.
With both packages installed, the Experimental Enable batching setting becomes available in the Sprite Skin component. As the implementation of the performance boost might contain bugs, you may switch back to the previous implementation by clearing the Enable batching option.
Sprite Skin component
When the character Prefab is brought into the Scene view, Unity automatically adds the Sprite Skin component to any Sprite that have any bone influences. This component is required for the bones deform the Sprite Meshes in the Scene view.
Disclaimer: The content on this site belongs to its respective owners. We don’t have any claims on images or content. The intention of this blog is Public Awareness / Knowledge base and providing insight to readers.
About p66 – www.p66.me
Headquarters in Newark, DE, United States of America. And having a production facility in Bangalore, Karnataka, India. P66 is one of the best 2D & 3D Production mushroom sized Creative Agency. Aiming to provide best creative services at a very affordable cost. P66 is a studio which is specialised in Traditional & Digital Type of Animation. It has provided contribution in the areas of 2D Animation, 3D Animation, Motion Graphics, Free-hand drawing, Drawing & Illustration, Digital Comic Books, Digital 2D Painting, Concept Artistry Drawing, 2D & 3D Game Designing, E-learning for kids
To provide a FREE Consultation about services of P66 do reach us on +1 (914) 247-7791 or Email us on :Reply@p66.me