In the last tutorial, we saw how to animate a simple object in Godot. In this tutorial, we will try to move an object using script. I am using Godot version 3.4.2 for this tutorial.
What you will learn
- How to create a new script.
- How to add the script to an object node.
- How to move an object using script
Let’s get started
1.Drag and drop the node to which the script needs to be attached to the scene view.
2. Select the node and go to the inspector window.
3. Click on the script property and select new script.
4. Give a name to the script and click add.
5. A new script is created and is added to your node.
Moving an object using script
1. Select the node and go to the script property in the inspector window.
2. Click on the down arrow in the script property and click edit.
3. The script editor will open up.
4. Paste the code below to move the player.
5. Press play and test the code
Player move script
extends Sprite var speed= Vector2(10,10) func _process(delta): position+=speed*delta