- Home /
Moving static colliders in Unity 2D
There's a lot of warnings about moving static colliders, but I'm a bit confused about static colliders in 2D.
I have an infinite runner game where the ground is spawned when the player moves. To avoid lots of Destroy and Instantiate calls I'm using a pooling system. The ground consists of groundblock gameobjects that simply have a box collider attached. No rigidbody. When the player moves forward, I'm effectively moving blocks from behind the player to infront of him. Hence, I'm moving static colliders - a big no-no. How do I remedy this? The approach in 3D would be to attach a rigidbody to my groundblocks, check isKinematic and change groundblock.rigidbody.position, which is a lot faster than groundblock.transform.position on a static collider. However, the Rigidbody2D doesn't have a position member, nor does it have a movePosition method.
What's the approach here?
hey bud, With rigidbody you either .AddForce();
or .$$anonymous$$ovePosition();
etc here is a link to rigidbody on the docs pages This will help you immensely, plus you are only ever adding a rigidbody to a gameObject as a component, so invariably, you will have access to the rigidbodies position member as it is the same as its parent holding Object (GameObject), which has transform to access its positional data.
Answer by CatchCo · Apr 02, 2014 at 04:46 PM
If the rigidbody is Kinematic you can just change Transform.position. If you scroll all the way to the bottom of the Rigidbody Component Documentation page you will find this line:
If you are directly manipulating the Transform component of your object but still want physics, attach a Rigidbody and make it Kinematic.
Essentially, Kinematic means that it's movements will not be governed by the physics system but it will still interact with physics objects.
Is there any explanation on why this is needed? I suppose the extra component overhead would still execute better than without it ?
@liortal please read the Static Colliders section that explains this with more details:
http://docs.unity3d.com/430/Documentation/Components/DynamicsGroupOverview.html
Your answer
Follow this Question
Related Questions
How can I make 2d sprites for Unity ? 1 Answer
code your own colision system i unity 0 Answers
Disable 2D Phsysics 2 Answers
(2D) Creating a border around the game 4 Answers