Hi, I have a reward chest in my game, which players can hit and open.
The thing I want to do is, when player opens the chest, some consumable items will bounce and spread around in random numbers. I’ve figured it out to instantiate them in random numbers but I couldn’t figure out how to make them bounce into different and random positions. By the way, these objects doesn’t have a rigidbody, but they have colliders.
Here is the code I am using to instantiate them;
public void CollectChest()
{
soulPointsIns = new GameObject[Random.Range(5, 10)];
for(int i = 0; i < soulPointsIns.Length; i++)
{
GameObject clone = (GameObject)Instantiate(soulPoints, transform.position, transform.rotation);
soulPointsIns *= clone;*
}
healthPointsIns = new GameObject[Random.Range(5, 10)];
for (int i = 0; i < healthPointsIns.Length; i++)
{
GameObject clone = (GameObject)Instantiate(healthPoints, transform.position, transform.rotation);
healthPointsIns = clone;
}
}
If anyone can help me about this, I’d be really happy, thanks in advance…
EDIT:
I’ve added a rigidbody and a new physics material as it was suggested, set the bounciness and friction to my needs, and I’ve changed the onTriggerEnter with a onCollisionEnter and that’s it! Thanks again for the help…