- Home /
How can I make two objects with rigid bodies that won't displace each other?
I have two GameObjects (we'll call them A and B). Either one of the objects can be controlled by the player at different points in gameplay. Both objects have a 2D boxcollider and a rigidbody to make them controllable and to keep them from going outside the playing field.
The problem is that I want object A to be immovable when object B is in play, and vice versa (object B is immovable when object A is in play).
Currently, if an object in play collides with an object not in play, it will move that object aside. This is unacceptable.
So, how do I make an object controllable, able to collide with other objects, and not movable by other objects?
why not disable the movement script to stop player from controlling you would disable colliders and rigidbody to stop collisions. or just set rigidbody to kinetic so it doesnt move.
Answer by Mazer83 · Oct 15, 2017 at 04:27 PM
To make an object immovable, you could do something like this:
Rigidbody2D rb = GetComponent<Rigidbody2D>();
rb.bodyType = RigidbodyType2D.Static;
Of course, you should consider cashing the rigidbody2D as a member, since doing GetComponent all the time is expensive.
You could then switch it back to kinematic or dynamic whenever it's appropriate.
Answer by finlay_morrison · Oct 15, 2017 at 04:24 PM
the only thing i can think of that would be quick and easy would be by turning the objects mass up loads
Your answer
Follow this Question
Related Questions
2D Box Colliders Overlapping On Collision 4 Answers
What's a good way at keeping a ball bounce around inside the scene? 1 Answer
Why does poligon collider 2d restricts movement of box collider? 0 Answers
Platformer2D Player sticks to platform corners 0 Answers
Ball bounces at different heights when it shouldn't 0 Answers