- Home /
(2D) Creating a border around the game
Hey, thanks for reading. Here's my problem, I have a bunch of circles that are bouncing off each other [(which looks something like this)][1] but I'm having trouble making borders for those circles to stay inside. My current solution is to generate 4 rectangles situated just outside the visible area all with Rigidbody 2D and Box Collider 2D with a Physics 2D material set to the Material of the 2D Box Collider. This works great at keeping the circles inside the area, but right as the circles bounce off the border they lose a lot (almost all) of their speed.
Currently I have the rigidbody 2D of the borders set at a very high mass, linear drag, and angular drag in order to keep them in place (which to me seems like a work around solution).
Basically, how I do create a prefab the elastically bounces off other objects without moving itself?
Thanks in advance! [1]: http://upload.wikimedia.org/wikipedia/commons/6/6d/Translational_motion.gif
Answer by ivomarel · May 01, 2014 at 11:28 PM
http://forum.unity3d.com/threads/210775-Rigidbody-2d-constraints
http://forum.unity3d.com/threads/211844-2D-physics-bounciness-issue
in the second link Berenger's comment fixed my problem! thanks for posting!
Answer by Pyrian · May 02, 2014 at 02:50 AM
It sounds like you're working with the Rigidbody2D of the borders, but if they're static, they don't even need that component and probably shouldn't have it. Instead, to control the bounciness of the walls, you need to look at their Collider2D, and specifically the bounciness characteristic of their Material. 2DMaterials are very simple, having only bounciness and friction, but if you don't set one, I think they're both zero.
Answer by Watmat · May 02, 2014 at 05:05 AM
Using Berenger's solution from http://forum.unity3d.com/threads/211844-2D-physics-bounciness-issue I was able to attach a script to 4 box2ds on the outside of my game acting as an outlined border
Answer by drop_m · May 02, 2014 at 10:55 AM
your solution works, you've only to set the Friction of the physics2D materials to zero