If your game object has a Rigidbody2D component on it, there’s a really simple way to get the thing moving — apart from the gravity-based physics that we played with earlier.
This method allows you to “push” the object any direction you want by adding a force to the X (horizontal) or Y (vertical) of the object.
Animation with AddForce (6:03)
At about 5:30 into the following video you’ll see me using a copy of the InstantiateGObj script — only this one is different than the last one we used. Oops! I made changes but neglected to explain what was happening, so watch this next very short video to see what’s what.
The New InstantiateGObj Script (2:45)
InstantiateGObj.js The New and Improved Version!
MoveObject.js (Phase 1)
A New & Improved MoveObject Script (Part 1 of 2) (7:03)
A New & Improved MoveObject Script (Part 2 of 2) (2:58)
MoveObjects.js (Phase 2)
Back to the Beginning 2D Game Development Dashboard