- Home /
how to make a pushable object in a 2D top-down game? (no gravity)
I am making a top-down 2D puzzle game that involves pushable boxes. Because it's top-down, I'm setting gravity to 0, which means that a box with rigidbody2D won't stop moving until it hits a collider. I would like to make this object not move unless it is touching the player (as the player pushes the box). How would i do this?
If it helps, both the Player and the box have boxcollider2D and their own RigidBody2D, both with gravity scaled to 0. Player has the tag "Player" and box has the tag "box". Levels will always have 1 player, but could range on how many boxes appear. I have a script attached to the player and hope that this code could also be attached to the player, but it overall doesn't matter.
Answer by Profile_6 · Apr 13, 2020 at 06:53 PM
SOLVED!
void OnCollisionExit2D(Collision2D colExt)
{
if (colExt.gameObject.tag == "box")
colExt.gameObject.GetComponent().velocity = Vector3.zero;
}
Your answer
Follow this Question
Related Questions
Prefab to a tile script 0 Answers
Difficulty with my tank game 2 Answers
Echolocation in 2D top down game 0 Answers
8-directional orientation, top down 2D, seperate from movement 0 Answers
How to have camera follow player unless it hits a boundary 1 Answer