Okay question looks a bit weird but its really easy actually. I am trying to make a simulation with 2D circles and one box. Each of them has collider and I would like to simulate each ball going random direction inside of the box. And If they hit the box, just collide and continue randomly going.
It looks to this when I start the simulation
Than this:
In the end all balls gather at the 4 corner but I am out of limit of my screenshots.
My dot script is like this:
public class humanAgent : MonoBehaviour
{
// Start is called before the first frame update
private Rigidbody2D rb;
public float speed = 1;
private SpriteRenderer sr;
public bool isInfected =false;
public Vector2 randomVector;
void Start()
{
sr = GetComponent<SpriteRenderer>();
rb = GetComponent<Rigidbody2D>();
randomVector = new Vector2(Random.Range(-1f,1f), Random.Range(-1f,1f));
rb.velocity = randomVector * speed;
}
// Update is called once per frame
void Update()
{
rb.velocity = speed * (rb.velocity.normalized);
if (isInfected) getInfection();
}
I tried to add physical material and played with friction / bounceness however didnt make any difference.