I want to attach my character to a fast moving platform(Train), but it doesn't work

I want to attach my character to a fast moving platform, but it doesn’t work.

I’m working on a 3D platformer game, and I want the player character to move freely on a long, fast moving train object. To be precise, like the train stage in Super smash bros, I want the character to move based on a moving train object, whether it’s on the floor or in the air (e.g. the character jumps while the platform is stationary → the character is still in the air, Start moving the platform → The character moves along the platform while falling in the air)

Reference - Super Smash Bros Ultimate 8 Player CPU Battle on Spirit Train(Hazards On) - YouTube

I placed the character on a fast-moving object and tested it, but it didn’t work as neatly as the super smash bros style I wanted. The jump distance was affected by the speed of the platform.

So then I attached the character to the object, the character flew over the object at high speed. In my opinion, the character’s base velocity was calculated twice. I’ve been searching for a few days and haven’t found a solution yet. Hope for help!

1 Like

Sorry to break it to you but In 99.9% of cases like this (including the ref vid), the train is stationary and the background is scrolling… :slight_smile: This makes pretty much all other aspects of the game much easier to code, especially the movement.

And knowing how the movement component works for characters in UE4, that’s the route I’d take in order to avoid rewriting core logic. Have a look here for a crude example:

https://answers.unrealengine.com/questions/1014733/endless-world.html

There might be better examples of scrolling backgrounds out there, though. But that’s the general idea.

Ah, makes sense. You could trace down from the player and check if there is a moving element underneath. If there is, transfer its velocity to the player’s Movement Component.

I can see it working pretty well, actually.

Thanks for the answer! The method you described is also very convenient and looks good. However, the game I’m working on right now is a way in which the user moves freely in one large level, and then gets on a small train moving fast along a path set on the map. And I want the user to be able to get off the train and jump nearby whenever he wants.

Try this, see if that does it:

Image from Gyazo

3 Likes

Thanks! I will try!

I found a solution that works exactly what I want! Now, even if I attach the character to the train, there is no problem with movement.
Just override the “void UpdateBasedMovement(float DeltaSecons)” function of the custom CharacterMovement component in C++. This function applies the velocity from the Actor the Character is standing upon to himself. If the character is attached to this actor he gets twice the velocity of the moving Actor.

source : https://answers.unrealengine.com/questions/141747/view.html

 void UMyCharacterMovementComponent::UpdateBasedMovement(float DeltaSeconds) {
     if (CharacterOwner->GetRootComponent() == nullptr || CharacterOwner->GetRootComponent()->GetAttachParent() == nullptr)
     {
         Super::UpdateBasedMovement(DeltaSeconds);
     }
     else
     {
         return;
     }
 }

When I tested it, it worked fine. However, it didn’t exactly match the way I wanted to move. I kept searching and found the solution I was looking for! Add the solution I found in the comments.

Which way did you find?

There’s a checkbox for this in the character movement component. Just select the component in the blueprint and uncheck “impart base velocity x,y and z” and you’re done.

4 Likes

Thanks, that was exactly what I was looking for! :slight_smile:

I have done the exact same thing, but it does not replicate. Everything seems correct on my server, and my client can move correctly, but when it looks at other clients and the server, they will continue to move in the direction they went when the attachment started! Any suggestions for replicating the movement to clients as well?

Hi, I know it’s been years, but that’s what I was looking for! Thank you! I could kiss you!

Did you try to replicate it? If so, did it work?