How can I make NPCs move around while inside a moving train?

Hi I’m implementing an NPC moving inside a moving train I’ve tried using Navigation Invoker to allow the NPC to move inside the train but I’m having the same problem as shown in the video.

Is moving train really required? Ie. It is because you cannot fake moving train in any way because of gameplay reasons like traveling between two destinations?

It would be much easier to have static train and move some kind of map around it. And if you want your whole gameplay inside moving train, just do static train and move level around. There will be a lot more problems (like shooting projectiles on that train, and adding trains velocity, or particle effects)

Nawrot has the right idea. though if the train must move…an idea comes to mind, though I’m not sure if it’s even possible, but try attaching a nav mesh volume to the train itself. Someone more senior in here may know if that’s even possible? I think of games like warzone, with its trains. Seems odd there’s never NPCs on them, probably with the way AI navigation works it just doesn’t work. Unreals AI reaction and control isn’t the fastest as it is. Id think you’d have to do some advanced c++ work to get something like this to work, you could also try attaching the actors to the train, and just move them around in local space, but again I’ve yet to experiment with anything close to this type of mechanic so I’m not entirely sure

Do I need to update the positions of nearby trees, mountains, and tracks every tick for them to move?

I think that yes you should do it. However maybe there is better way to make world moving.

So for creating moving actor:

  • make new blueprint actor, name it BP_MovingParent
  • add some debug mesh to it, (something that you can see in game)
  • add boolean variable SeeDebug? make it editable per instance
  • in construction script change visibility of that debug mesh to what is in SeeDebug?

Now Creating some children blueprint classes:

  • crate child class for BP_MovingActor
  • add there your game mesh, or multiple meshes, or even section of world outside train

When you have few of those moving actors sections, you can place them in level and work on moving logic.

best would be doing it with event dispatcher (so you have central place that manages all of them):

  • create your custom game mode blueprint, set project settings to use that instead of defaults
  • in game mode create dispatcher. like DISPATCHER_MOVE
  • in BP_MovingParent get game mode assign to dispatcher
  • Now add logic for moving when dispatcher is called. You can use just event, or you can give vector trough dispatcher.
  • you can also use linear interpolate on tick in parent actor on tick, and use dispatcher to set new targets like speed or direction.

Thank you so much! Everything is working fine.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.