Godot Version
v4.2.2.stable.official [15073afe3]
What I’m building
I’m creating a game involving trains.
I’ve got moving along the railway working using Path3D <- PathFollow3D <- RemoteTransform3D
. The RemoteTransform3D
is linked to my player which is currently a CharacterBody3D
.
I’ve also got tilting working based on the curve of the track and the trains speed. The tighter the bend and the faster you are going the more the train will tilt (rotate). If the train tilts too far then it will derail.
What I want to achieve
When the train derails it crashes and interacts with the environment until it gets reset a few seconds later.
What I tried
I’ve managed to get the physics engine to take over in the event of a derail, but I realised CharacterBody3D
doesn’t take into account a bunch of physics stuff. For example, even though the train is rotated it doesn’t continue to rotate and fall over onto it’s side, the rotation stays the same.
So I started to think maybe using a RigidBody3D
, which seems to handle all the physics stuff. However, it sounds like manually moving a RigidBody3D
is a bad idea?
I also realised during normal gameplay, I’m not actually using any of the CharacterBody3D
methods to move the player, which feels like a bit of a smell.
My ideas
- Use
CharacterBody3D
and implement the missing physic interactions. - Use
RigidBody3D
and reimplement my railway moving/tilting code to use physics. - Use
RigidBody3D
while keeping my existing railway movement/tilting code. - Spawn a
RigidBody3D
at the point of derailing, and hide the player node.
One, seems like a lot of work to implement the physics which would already be handled by RigidBody3D
, so I’m not really liking that idea.
Two, I have no idea how I’d use physics to move the RigidBody3D
while also constraining it to follow the Path3D
?
Three, I’m not sure how to stop my movement code fighting/desyncing with the physics engine? Also how (if I needed too?) I could reset the RigidBody3D
when the train resets back onto the track?
Four, seem like it might be the easiest? However, I’m not entirely sure how to do this yet.
Help!
Any help or advice is very much appreciated! I’m happy to hear completely new ideas as well.
FYI, I’ve got a lot of general programming experience but none in game development. I started messing about with Godot a few weeks ago, so sorry if this doesn’t make any sense!