You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

1 D铆as
17 Hrs
27 Min
52 Seg

Moviendo las piezas

12/34
Resources

How to add motion to your pieces with DotTween in Unity?

Welcome to the world of motion in Unity! If you are looking to add motion capability to your parts in an efficient and fluid way, the DotTween tool is your perfect ally. In this class I will guide you step by step to make your parts move the way you want them to. Let's start bringing your project to life!

What is DotTween and how to install it in Unity?

DotTween is a powerful asset from the Unity store that provides animation tools to achieve smooth and natural movements. Here's how to add it to your project:

  1. Google search: Type "Dot Tween Unity" in your browser. Look for the link to the official Unity store.
  2. Add to your assets: Log in to your Unity account and press the "Add to my assets" button. Then, select "Open in Unity" to start the integration process.
  3. Import packages: Once in Unity, open the Package Manager and you will find DotTween. Select "Import" to add the necessary scripts and assets.
  4. Initial setup: Go to Tools > Dot Tween > Dot Tween Utility Panel inside Unity, and click "Setup DotTween" to complete the installation.

How to write a motion function in C#?

Now that you have DotTween ready in your project, it's time to program the motion in your scripts. Let's write a simple function that receives target coordinate parameters:

using UnityEngine;using DG.Tweening; // Include the DotTween library
public class MyScriptPiece : MonoBehaviour{ public void Move(int destX, int destY) { transform.DOMove(new Vector3(destX, destY, -5), 0.25f) .SetEase(Ease.InOutCubic) .OnComplete(() => { // Update position this.x = destX; this.y = destY; });} }} }
  • DO Move: Allows moving the object to a specific point in a specific time.
  • Set Ease: Adds smoothness to the movement, giving it naturalness.
  • On Complete: Updates the object's position after completing the movement.

How to test motion in Unity?

To verify that your motion function works correctly, you can set up a test function inside Unity:

public void MoveTest(){ Move(0, 0); // This is a test point}
// Decorator to make the function accessible from Unity[ContextMenu("Test Move")].

This code snippet creates a simple test to see the move in action. Once you load the script, when you click on the Unity context menu (the three dots on the component), you will see the "Test Move" option. When you select it, your parts should move to position (0, 0) in the stipulated time.

Recommendations for quick tests

If you want to quickly test functionality without altering your code base too much, use decorators such as ContextMenu. With them, you can evaluate the behavior of functions directly from the Unity editor without having to change the input values.

How to control and customize the movements?

The next step is to develop a system that allows you to control when and where your pieces move according to your game requirements. You can experiment with different time values and Ease types until you find the exact effect you are looking for.

Explore the settings and soak in the possibilities that DotTween offers. With each setting, your digital world will become more authentic and dynamic - there are no limits to your imagination!

With these steps, you are now equipped to generate stunning movements in Unity. Remember that practice is key; keep exploring, tweak parameters and discover what DotTween can offer you in your game creation journey. If you have questions or experiences to share, leave your comments, we'd love to hear from you!

Contributions 3

Questions 3

Sort by:

Want to see more contributions, questions and answers from the community?

Pueden descargar el paquete de la Unity Asset Store Dando click aqu铆

Lo unico diferente que tengo es que al momento de ejecutar el "Test Mode" me pone la pieza abajo de la que esta en la coordenada (0,0). Pero si agrego un "-6f" ahora si aparece sobre la pieza de la coordenada (0,0) pero al momento de mover otra pieza igual se va por abajo.

Amo este curso. Gracias!