Random movement for objects

How can I get objects to move around like this?

members.iinet.net.au/~pontipak/redsquare.html

so far i’m spawning objects and which have the following script attached to them:

public class ConstantMove : MonoBehaviour {
	private float fSpeed = 4f;  // Units per second of movement;
	
	void Update () {
		transform.localPosition = transform.localPosition + -transform.forward * fSpeed * Time.deltaTime;

So far the object will only move in a straight direction along the z axis once spawned. Am I going about this the right way or is there a better method?

Random.Range() is a function that will give you back a random number within a range you specify.

I suggest you use this function to generate a random 3d vector, and add THAT to your transform.localposition.

You can use the range values passed to the random function, to limit the distance any given random change will move the object.

Alternatively, and perhaps for a more smooth looking result: you might wish to add a rigid body to your object, and adjust it’s VELOCITY rather than it’s position, with a random 3d vector.