Topic was automatically imported from the old Question2Answer platform.
Asked By
G T Manoj
I’m new to GoDot Game Engine. I’m trying to create a 2D game in which I want to move a 2D car object on a curve route programmatically. What is the right node to be configured to achieve this, I’m trying to use VehicleBody which is a 3D node, is this the right way to do.
Since you’re new to Godot I suggest you step away from what are called spatial nodes for now(3D nodes like Vehicle Body). When you said “move a 2D car object on a curve route programmatically”, you meant on its own in a constant path? If so, then Path2D and PathFollow2D are just what you need. Follow these steps.
Add a Path2D node to your scene.
Create a path using said node. Notice the new buttons on the top? The one with the plus symbol makes add a point by clicking on the point in the editor where you want it.
Once your done creating a path of points, create a PathFollow2D as a child of this node(to do that just add a node while the other node is selected).
Now it’s time for your car.
Assuming you’re car interacts with physics, create a kinematicBody2D node first. And as a child of that, a CollisionShape2D and a Sprite. The Sprite’s texture will be an image of your car, and your CollisionShape2D should have a collision shape of whatever you want. Preferably a capsule.
Give your car(the KinematicBody2D node) a gdscript. You do know what a gdscript is right?
In the GDscript remove everything and type the following-