I am making a simple 2D drone game where you control a drone up/down/left/right with the arrow keys and can pick up boxes by touching the top of them. The player has a RigidBody2D and BoxCollider2D
The Anchor child object is just an empty object to contain the location where the child object will be placed when collected, e.g.
Now, the problem I’m having is that when the winch touches a Parcel object, it adds it as a child and sets the correction location, which is fine. However the drone automatically flys up when an object is picked, which I don’t want.
If I scale the Parcel objects a little smaller, the drone still goes up, but not as fast.
Seems a bit wonky indeed. My first guess is that the colliders are overlapping and both have rigidbodies. You set the parcel position to the exact same position as the drone, or box as you named it in the hierarchy, so the drone and parcel’s colliders are overlapping. The parcel’s rigidbody is set to kinematic so it wont fall and you’re getting a strange physics reaction which constantly pushes up because the parcel technically cannot move but is parented to the drone so it will constantly be at the transform.position (of the drone) you put it at.
Potential solution: Add a empty gameobject called Parcel Position or Pickup Position and have it be a child of the player, and lower it a bit below the box’s collider. Then, make a reference to your script to that new transform and have the parcel still parent to the Box or Player, but set its transform.position to that of the new transform object. If it still does it, lower that transform object a lot and see if it still does it.
There are probably 53.5 different ways to solve this but this is what my brain thought of. Let us know if it doesnt work
You were absolutely spot it, it turned out to be that when the box was collected and re-positioned to the anchor, the anchors box collider was overlapping with the drones box collider Thank you so much for your help, you’ve just made my weekend! I hope you have a brilliant day!