Moss Giant Animation

Hal Brooks
3 min readOct 23, 2021

Objective: Implement Idle and Move animation for Moss Giant in Unity.

Animated moss giant moving from pointA to pointB, and back.

The Moss_Giant game object has the structure shown below with three children: pointA, pointB, and Moss_Giant_Enemy. The parent Moss_Giant is an empty game object used to organize the other objects.

Moss_Giant organization

Moss_Giant_Enemy is shown below, and contains the rigidbody2, box collider 2D and MossGiant script, noting the variables derived from the Enemy base are assigned in the inspector. Both pointA and pointB are empty game objects used to store path information for movement of Moss_Giant.

Moss Giant Enemy

Moss_Giant_Enemy also has a child object, Sprite, which contains the SpriteRenderer and Animator for the Moss_Giant.

Sprite containing Animator & Sprite Renderer.

The Animator for Sprite has two animations, Idle and Walk, with Idle being the default animation. The animator uses an Idle trigger parameter to exit the Walk animation.

The Idle animation uses Has Exit Time to transition to Walk, see below.

Idle -> Walk transition.

The Idle trigger is used as the condition to transition from Walk back to Idle as shown below.

Walk -> Idle Transition.

The MossGiant script component of Moss_Giant_Enemy is derived from the abstract class Enemy. The required variables are inherited and can be assigned in void Start(). Both anim and spriteRenderer use GetComponentInChildren to retrieve the components from the Sprite child. The other variables were assigned in the inspector for Moss_Giant_Enemy, shown above.

The Enemy base requires a void update method in the MossGiant script shown below. If the moss giant is in the Idle animation the return statement skips the MoveGiant() method. This allows the giant to remain stationary during Idle animation.

Override void Update in MossGiant script.

The MoveGiant() method below uses Vector2.MoveTowards to move the giant to the target. If the giant’s target is pointA, i.e. the Vector2.Distance is zero, then flip the sprite on the x-axis. Otherwise, the sprite maintains its original orientation, i.e. flipX = false. If the current position for Moss_Giant_Enemy is equal to pointA the target is set to pointB, and vice versa for pointB. Regardless the parameter Idle on the Animator is triggered to enter Idle animation when a target is reached.

MoveGiant() method in MossGiant script.

This implementation of MoveGiant() is simpler than my previous article.

This article uses assets from GameDevHQ Filebase.

--

--