Move the player(cube) to the enemy(cube) by clicking on enemy?

Hello! How is it possible to make a game object move to another by clicking on that other game object? Something that has to do with Vector3.MoveTowards or something perhaps? any tips?

You can use the Transform.Translate function (of the Player cube). You should specify the direction (enemyPosition - playerPosition) and the distance.

For example:

Vector3 direction;
bool shouldMovePlayer = false;

void OnEnemyPressed()
{
direction = (enemyGameObject.transform.position - playerGameObject.transform.position).magnitude;
shouldMovePlayer = true;
}

void Update()
{
if (shouldMovePlayer)
{
playerGameObject.transform.Translate(direction * Time.deltaTime);
}
}

I hope I understood your question correctly :slight_smile: