What about using Navigation? As you said wandering, I thought it would give you a nice result and also make your code simple.
The following screenshot is a sample with Navigation. The moving game objects are also changing their direction nicely, although it cannot be seen in the sample because the game object is capsule...

Ground game object in the sample program has NavMesh. See here to build NavMesh.
Agent game object has NavMeshAgent Component. See here to set it up.
Th Behaviour class below is for Agent game object.
using UnityEngine; using UnityEngine.AI; public class NavAgentBehaviour : MonoBehaviour { public Transform[] Destinations { get; set; } // Use this for initialization void Start () { InvokeRepeating("changeDestination", 0f, 3f); } void changeDestination() { var agent = GetComponent<NavMeshAgent>(); agent.destination = Destinations[Random.Range(0, Destinations.Length)].position; } }
The next Behaviour class is just for spawning the Agent and setting up the destinations. On Unity, set it to whatever game object in the scene, and allocate game objects to the fields.
using UnityEngine; public class GameBehaviour : MonoBehaviour { public GameObject Agent; public Transform SpawnPoint; public Transform Destination1; public Transform Destination2; public Transform Destination3; // Use this for initialization void Start() { Agent.SetActive(false); InvokeRepeating("Spawn", 0f, 2f); } void Spawn() { var newAgent = Instantiate(Agent); newAgent.GetComponent<NavAgentBehaviour>().Destinations = new[] { Destination1, Destination2, Destination3 }; newAgent.transform.position = SpawnPoint.position; newAgent.SetActive(true); } }
Increase the number of destination, to make the moves look more random. By the way, the destinations do not need to be specified by game objects, which is only for making it easy to see the sample program's behaviour.