How to make a 2D object move with constant speed

I’m new to unity and wanted to know how to make a sprite move with a constant speed.

That depends on the type of you object and other stuff.
Does the object have a rigidbody component attached? > AddForce(), etc.
No rigidbody? > update the objects position via transform

I’m trying to do it without a rigidbody2D component. I want the sprite to bounce off colliders without losing speed as well. I think you reverse the velocity or something?

Velocity is a rigidbody attribute.

Could you please show your actual code to have something to start with? Thanks!

1 Like
using UnityEngine;
using System.Collections;

public class Speed : MonoBehaviour {

    public float speed = 2.0f;   
   
    void Update () {

        transform.position += transform.right * speed * Time.deltaTime;
   
    }
}

How can I set the original direction of the of the moving object? Is it through Vector2?

Hm I am not sure if I do get you right, sorry. Moving into the opposite direction would be:

transform.position += -transform.right * speed * Time.deltaTime;
1 Like

Cool! It worked with my enemy script!