When we are developing games then sometime we need an object which generate from a position and move by itself in a particular direction. So here is the simple code from which yo u can do this.
You just make your object a prefab and add a script that have this below code written in it. And then instantiate your object at a particular point .
private Rigidbody rb;
public float speed;
void Start () {
rb = GetComponent<Rigidbody>();
rb.velocity = transform.forward *speed; // now your object will move in forward direction
}
0 Comment(s)