Godot Version
4.4
Question
Hi. I’m new to Godot 4 and would like to ask a quick question if I can. I’m not asking for details. Just looking to be pointed in the right direction. I’m trying to make a slot car game and need the cars to follow a groove. I’ve looked a little into path#D following but the tracks vary in designs. So, as I see it, I need a way for the car to actually follow the groove in the track with physics or the scripting to generate the path in code (if that’s possible)? The car also would need physics so it can crash and fall off the track if too quick in a corner.. If you were trying this, what direction would you go in? Hope you have a minute to answer. I’m stuck and it seems like it should be a simple thing to accomplish. Thanks. Jim
You can add a Path3D
(or even multiple Path3D
s) to every course you make.
I haven’t really ventured much into 3D, but I’ve used NavigationAgent2D
before and it appears it has a 3D counterpart. My naive approach would be to start from there.
I’d think for something like this, you’d want to use the path system, but instead of attaching the car to the path you’d want to determine the closest point on the path to the car, and if the car is within some small distance of that point apply a large physics force attracting the car towards that point. If you have other forces (like inertia in corners…) then depending on how you tune the forces, the car can potentially overcome the path’s attractive force and go flying off the track…
I’m making a train game, which has basically the same requirements.
Simplified I currently use Path3D
with a RemoteTransform3D
that points at a RigidBody3D
.
The RigidBody3D
is set to freeze = true
and freeze_mode = FREEZE_MODE_STATIC
. I manually calculate velocity and use that to update the progress
along the Path3D
.
To enable crashing I set the RigidBody3D
to freeze = false
and the RemoteTransform3D
update_position = false
. This let’s the physics engine take over and collide with everything.
This seems to be working pretty well so far.
This is the post I originally made with some more details.