- Home /
Rigidbody2D hanging/grabbing another Rigidbody2D
I'm very new to Unity so please bear with me, I'm currently experimenting.
I want to create a situation where a player can jump across/through an object but if they press a key while passing across/through the object, they effectively grab hold of the object, this object may then move (I guess it is similar to a rope but the object is, say a large rectangle, maybe it's more like a zip wire)
Now I have edited the projects Physics2D so the player does not collide with the object he wants to grab hold of, this other object being another rigidbody2d, and I have implemented the code to do the key input, when the player hits the key at the right time I then add a HingeJoint2D between the player and the grabbed object, I then apply a force to the object being held (relative to the players velocity when he grabbed it) so the player is pulled along with it. I don't really want the player dangling about I want him to be pretty much fixed in place (which is why I'm currently using a HingeJoint2D, other joins made the player jitter too much). The problem I'm having at the moment is that the hinge has default values and so no matter where the player is when he presses 'grab' he is always hinged on the left hand side of the object.
So my questions are
A) Am I going about this all the wrong way (I'd like to keep things simple to begin with so I don't particularly want to get into Kinematic rigidbodies just yet I'd like the world to take care of movement for now)
B) How can I calculate where to put the hinge in order that the player is stuck where he pressed 'grab' i.e. how can I calculate local coordinates for both the player and the object that lie on top of each other in world coordinates.
Any advise appreciated