Endless runner constant movement help!

Hi I’m trying to create and endless runner and I need help with constant movement. I’ve been able to get it working for my character, but I want him to be followed by something that is moving the same speed as him ?

this is what i’ve tried

public float speed = 6.0f; (same speed as my character)

void FixedUpdate();
{
rigidbody2D.velocity = new Vector2(speed, rigidbody2D.velocity.y);
}

An unexpected symbol error message keeps appearing for the word new.
I really don’t understand, if anyone could give me some advice it would be great. I’m probably doing this completly wrong because I’m new to unity. Any alternative would be welcome to thanks!

If it’s a platformer you could do:

transform.position += Vector3.left * speed * Time.deltaTime;

Or you could use transform.translate.

hi thanks for your help. the code works, except that when I change the left command to right the gameobject dissapears??

Rather than moving both objects separately, you might find it works better to just set a specific follow distance:

public Transform character;
public Vector3 offset = new Vector3(-0.1f, 0f, 0f); // Slightly to the left of the character
void FixedUpdate();
{
transform.position = character.position + offset;
}
1 Like

Thanks got it working in the the end. Set it up with its own float so that I could adjust his speed . thanks!