Skip to main content

Moving and transforming

One of the tools which can be used to improve your workflow are Animations. Animations are a way to move and transform GameObjects in an easy way. To be able to use these Animations and tween GameObjects you have to start by including the ExtensionTools namespace on top of your file.

using ExtensionsTools;

Moving and transforming a GameObject

Using animations to move GameObjects are very easy. By default transforms already have extensions to do some basic animations such as a simple move, scale, and rotate.

The easing type is an optional parameter which changes the way the animation will be interpolated. Some examples of some of the easing types can be found here

transform.MoveTowards(targetPosition, time, ExtensionTools.Animations.EasingType.SmoothInOut);
transform.RotateTowards(targetPosition, time, ExtensionTools.Animations.EasingType.Linear);
transform.ScaleTowards(targetScale, time, ExtensionTools.Animations.EasingType.ElasticInOut);

Additionally you can use a parabolic movement to simulate for example a grenade throw or a jump:

Vector3 upDirectionandHeight=Vector3.up*5f
transform.MoveParabolicTowards(targetPosition, upDirectionandHeight, time);

Playing Custom Animations

Instead of using the built-in extensions, you can also use the PlayAnimation Method to play an Animation on your transform such as the Shake Animation in which the first two arguments are the starting position and starting rotation.

using ExtensionsTools.Animations.Presets;

...

transform.PlayAnimation(new EShakeAnimation(transform.rotation,transform.position,rotationShakeAmount,positionShakeAmount),time);

Stopping Animations

To cancel these animations all you have to do is call:

transform.CancelAllAnimations();

In the next chapter you will see how you can create your own custom animations to play.