hey guys, i’m having an issue with choosing a target for my game object.
i have five rolling balls and also 5 target (empty game objects) destinations for these balls to go to.
there is a trigger box in my scene.
what i need here is that as the balls are rolling and entering the trigger box.
i want them to choose randomly among the target destinations that i set up before and move toward them. and when the ball reaches its destination it should occupy that target place so that the other balls could not get in there again.(two balls should not be placed in the same spot). finally when the five balls are inside the trigger box , all the target places should be filled.
is there any way to achieve that?
this is the script i’m using to move the ball toward a target position
public class objfollew : MonoBehaviour {
public GameObject target;
public float moveSpeed;
public float rotationSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position = Vector3.MoveTowards(transform.position, target.transform.position, moveSpeed * Time.deltaTime);
Vector3 vectorToTarget = target.transform.position - transform.position;
float angle = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
Quaternion qt = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.RotateTowards(transform.rotation, qt, Time.deltaTime * rotationSpeed);
}
}
thanks