Hello,
This is my first tutorial here, so I apologize if things don't go smoothly.
In this tutorial we're gonna learn how to make objects attracted to your mouse pointer. in fact, you can simply specify an object type as Metal for instance and have fun with all the ideas that you'll get.
Sprites
You can use your own sprites.
Let's get started.
Basic Setup
- Add a Sprite by double clicking on an empty place of the layer.
- Load the Magnet image and close the image editor.
- Rename it to Magnet.
- Then add a Mouse Input object.
- Go to your Event sheet and simply add a Every tick System Event.
- As Action, choose your Magnet object and Set position to Mouse.X and Mouse.Y
- Add another sprite and this time, select the box image.
- Add a Physics Behavior to our box and set Immovable to Yes.
- Make an environment with the box object, doesn't matter how simple or complicated, just make sure you have a ground.
- Now add another Sprite and select the metal image.
- Add a physics behavior and don't change anything.
- Bring the magnet to the top layer by simply placing it on the other objects and choosing Z Order -> Send to top of layer from the Right Click Menu.
Your scene should be something like this by now:
Aiming
You've probably thought of this, isn't it cool if the magnet faces to our metal object ? well of course it is. let's see how to make it.
- You might wanna give your metal object a name, for instance "Metal".
- Go to the Event sheet tab.
- We already made a System tick event, lets add another Action to it.
- Add a Set angle toward position action to the Magnet object.
- for X and Y, enter Metal.X and Metal.Y
Feel free to have a test run.
Isn't it cool ?
Now the most important part.
Make the Magnet work !
- Add a new Mouse button is down event.
- For action, Pick Metal and select Apply force towards position.
- Set the values using the picture below.
Now run your project and hold your mouse left button down. see ? the magnet absorbs the metal ! that was simple wasn't it ? Now use your creativity to use this to make a game :)
You can download the final project HERE.