- Home /
Question by
Slastraf · Jan 24, 2019 at 05:33 PM ·
movementphysics2d gamerigidbody2d
How to make a 2D Player move a box properly ?
I want to make a game like Zelda where the player can move the box when he is near it. I have tried to come up with some solutions, but they always seem very bugged or overcomplicated, like getting an array of collider contacts, and then evaluating if theres a wall nearby and so on. I am sure some of you have seen it somewhere online ? or can help me otherwise ?
Comment
Answer by Magso · Jan 25, 2019 at 12:34 AM
The simplest way is checking the distance and parenting the box to the player.
float closeEnoughToMove;
if(Vector3.Distance(box.transform.position, transform.position) < closeEnoughToMove){
box.transform.parent = transform;
}
and to stop moving the box
box.transform.parent = null;