First post and total Unity n00b here! Please bare with me :D

I'm trying to make the player a child of a moving object (a train) upon spawning. Normally I'd have a script of transform.parent involved, but I'm stuck since the player does not technically exist until they spawn. Right?

I looked around in the framework Events area, but was not entirely sure which one would be able to do this type of request. I'm hoping there is an event that can do this, because in future I'd like the player to once again be able to become a child of a train for a train ride.

Thanks in advance for the help, and if I'm being an idiot and completely missed something totally obvious, please tell me.

[[Overlong explanation of what I'm attempting is here in case I'm doing this wrong. If you already know how to help me and want to skip this, go right ahead!]]

I want the player to start the game on a train to their destination. Easy enough to spawn them inside the train prefab.

Unfortunately, if you just spawn the player into a moving object, the player and the train have two different speeds and apparently two different physics, so the train "drags" the player along. Totally not ideal.

I want the player to be able to walk around on the train like in real-life, and the only way I've been able to successfully do that so far is to make the player a child of the train. Hence the need for this particular solution!
  • I could benefit from this knowledge also, I tried a couple things but no real success. I know Playmaker has nodes for 'get child' and 'set child' but there has to be an easier way than adding another entire ecosystem.

    If you don't want the player to be able to move around on the train, and just want him there while the train does its thing, you could try this: player interacts with train, the interaction event would hide/destroy the player model and set the train as the player, and then sends a move event to make the train/player go to its destination, and then bring back and switch control back to player.
  • edited December 2018
    There's the Mount Object node for doing this via game events. If the player is spawned by an event, just use that node after spawning the player. Otherwise, try setting up an event interaction with the Trigger Enter start type on your moving object, so that the spawning player starts the event.
    Post edited by gamingislove on
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • Thanks for the reply, both of you! I'm going to try the Mount Object node first thing I do when I get back to work, and give an update if it works how I wanted it to. :D
Sign In or Register to comment.