# My Earthbound-like Movement Script works in Unity Gameview, but runs differently in Gamebuild

First programming question I've ever made in my short journey. I'm trying to create a script which moves members of your party in a line behind you (think Chronotrigger or Earthbound). Here's a clip of what I want it to look like.

Problem: Everything looks fine in the Game window when I play, but when I build the game to test, the characters begin to stack one on top of each other. I assume it has something to do with Update() frames dramatically increasing the frequency with which I enqueue the positions of the leading character (although I'm not experienced enough to say for sure, clarification on this would be helpful).

• I've tried increasing the offset, but this solution is variable depending on the players computer fps so that wont work.
• I've tried running both scripts in FixedUpdate() but a lot of my other systems run on Update() and so everything stutters.
• I've tried enqueue'ing from an IEnumerator and waiting for .1 second between each enqueue but that stutters as well..

What I'm doing: The leading character has a script called PlayerTrail which creates a Queue of Vector3s. In Update the game object's transform.position is enqueued. The following character has a script called PlayerFollower which looks at the Queue and Vector3.MoveTowards the position, then dequeues that position and repeats. Each character only looks at the trail of the character in front of it.

Everything seemingly works fine and well in the Unity program, this issue only arises once I build the actual game.

Code Supplied Bellow:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerTrail : MonoBehaviour
{
public Vector3 LastMovement;

private void Start()
{
}

private void  Update()
{
if (this.transform.position != LastMovement)
{
LastMovement = transform.position;
}

}
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerFollower : MonoBehaviour
{
public int Offset;
public int moveSpeed;

private Animator animator;

void Start()
{
animator = gameObject.GetComponent<Animator>();
}

void Update()
{
{
animator.SetBool("isMoving", false);
return;
}
else
{

animator.SetBool("isMoving", true);
animator.SetFloat("moveX", direction.x);
animator.SetFloat("moveY", direction.y);

Debug.DrawRay(this.transform.position, direction);

}
}
}


• In the video they keep a certain min distance if you do not move at all. Do they keep that in your editor version (the working one as well) when you do not move or do they stack there as well? Maybe your offset is better used as an offsetDistance to the person in front of you and not about how many vectors are in the list (which is dependend on how fast you populate the list) Mar 4 '21 at 8:18

Instead of a counter of how many items you have in your queue, you should only move them towards the next part when they are further than a certain distance. Removed the animator for testing purpose. They try now to catch up to you as well in case you do not move or move faster than they can. You want as well to only dequeue the position once you reached it (or when you are close to it) to not stop moving towards it in case the player moves faster or they get stuck for a second (else the distance might get bigger between the followers)

Last you wrote that the character only looks at the character in front, but from your question it sounds like that only the leading character has the playertrail script. You should rather place a playertrail on each character you want to follow, means that if you have 4 Characters, you have 3 playertrail scripts (on 1, 2, 3) and 3x Followerscript (on 2, 3, 4). This way you have better control over the distance between the characters (this might be important if the size of characters is different). And the character does not need to know how many characters are in total to calculate different offsets.

public class PlayerFollower: MonoBehaviour
{
public float keepDistance;
public int moveSpeed;

void Start()
{
}

void Update()
{
{
moveSpeed * Time.deltaTime);
Debug.DrawRay(this.transform.position, direction);
}