How do you make a clone travel at a fixed velocity in the direction of its rotation?

For example if a clone spawns and has values of (0, 0, 0, 1) it travels to the right at a set speed.
How would I script that in C# ?
Thanks in advance!

It depends on what you’re going to do with the object and how (if at all) it interacts with other objects. For simple non-physical movement, you can do something like this:

using UnityEngine;
using System.Collections;

public class MoveAlongAxis : MonoBehaviour
{
	public float moveSpeed = 5f;
	public Vector3 moveDirection = Vector3.forward;

	void Update()
	{
		transform.Translate(moveDirection * moveSpeed * Time.deltaTime);
	}
}

Time.deltaTime is how long the current frame took to render. When multiplied to a speed variable, it adjusts the speed to the framerate. So for instance in the above code, moveSpeed is set to 5, so when multiplied to Time.deltaTime it will make the object move at 5 units per second.

moveDirection is the axis the object will move along. Vector3 contains definitions for each of the axis. ‘forward’ is the Z axis, ‘up’ for Y, and ‘right’ for X. When used in the Translate method, it defaults to using local axis. If you need to move by setting the object’s position manually, then you’ll need to use transform.forward instead of moveDirection to get the local axis.

transform.position += transform.forward * moveSpeed * Time.deltaTime;

If you need physics, then the object will have to have a Rigidbody (or Rigidbody2D) attached. Again for simple movement:

using UnityEngine;
using System.Collections;

public class MoveAlongAxis : MonoBehaviour
{
	public float moveSpeed = 5f;
	Rigidbody myRigidbody;

	void Start()
	{
		//Store reference to the game object's rigid body. GetComponent is slow.
		myRigidbody = GetComponent<Rigidbody>();
	}

	void FixedUpdate()
	{
		myRigidbody.MovePosition(transform.position + (transform.forward * moveSpeed * Time.fixedDeltaTime));
	}
}

If using 2D system, replace all Rigidbody with Rigidbody2D.

Issue with this is if it gets blocked, it will constantly try to move, which may or may not work depending on how you want your game to run.

With physics you also have the option to just apply a force when it’s spawned and let the physics system handle movement from there. You can either use the Start() method, or on the spawner script to trigger this. This is good for things like bullets or other projectiles.

myRigidbody.AddRelativeForce(moveDirection * moveSpeed, ForceMode.Impulse);