Bear
Bear

Reputation: 31

Unity Making a prefab collide with surroundings, but not other objects of the same prefab

The picture below is my simulation, and the problem im facing is that they wont collide they way i want to. My game project

I made them move randomly and i want this behavior.

  1. The green balls are supposed to "bounce" off the outer grey walls, so collide with them (simulate physics)
  2. The green balls are NOT supposed to bounce of each other, but only do triggerevents (so i know when they are on top of each other)

How do i do this. I have looked at multiple tutorials and i simply dont know what to do. As far as i understand, to make a collision, one of the objects has to have a rigidbody on, and the other a normal collider?

enter image description here

I have to tried to follow this overview. The balls are from the same prefab, so to get a trigger for them i have to pick either static trigger collider, rigidbody collider trigger, or kinematic rigidbody trigger collider (as seem from the overview). BUT if i pick any of those i cant get a collision with the walls? Do i have to do the wall collisions myself?

Upvotes: 1

Views: 573

Answers (1)

Jadon Wolfgang
Jadon Wolfgang

Reputation: 180

What you can do is make all the walls static colliders, and make a script on all the balls that check whether they hit a wall or a ball. and do actions that way.

Or

Make the walls check for a collision with the ball and add a force to the negative direction that they came from or something.(up to you how you want the balls to behave)

for example :

  OnTriggerEnter(collision other)
  
  if(other.transform.tag == Ball)
   //Run Some Code here
   // for example
   BallRb other.GetComponent<RigidBody>();
   BalRb.addForce //add the force that you want.

Upvotes: 1

Related Questions