Download

How to stop character moving with floor?

Hi everyone
I setup a floor moving along the X axis.Now my character is moving with it.How can I stop the character moving with floor so if the player don’t jump the chatacter will fall from the end of the moving floor?

Get the velocity of the moving platform, multiply it by -1 and add it to the players velocity, this might get glitchy though.

If you’re using the default character, then in the movement component cpp file there is this function:


void UCharacterMovementComponent::UpdateBasedMovement(float DeltaSeconds)
{
    if (!HasValidData())
    {
        return;
    }

    const UPrimitiveComponent* MovementBase = CharacterOwner->GetMovementBase();
    if (!MovementBaseUtility::UseRelativeLocation(MovementBase))
    {
        return;
    }

    if (!IsValid(MovementBase) || !IsValid(MovementBase->GetOwner()))

//...



And I’m suspecting that function has to do with it? So maybe you can inherit from UCharacterMovementComponent and just add an override to that function (since is virtual) which exit from the function based on a variable you control, like “bIsOnActiveMovingPlatform”

And then if your character inherits from C++, you can unregister the default move component and register this new one from the C++ constructor, I believe.

But is all speculation, I don’t really know :slight_smile:

Hi Orkeny,Thanks for your idea.I tried on a test project.It worked but the character was shaking,may be because of the inaccuracy in real time,and it may get tricky if I put some other movement into the game.But thank you anyway.

Hi ,thanks for your reply.
I’m not familiar with C++.It seems that the only way to add a subclass of UCharacterMovementComponent to an actor is through C++ because it’s an actor component, is that right?

I don’t know why actually :stuck_out_tongue:
Though maybe the problem multipling by -1 is that you get small floating point rounding imprecisions? Instead I would try setting a bool on the character when your platform is moving, and when the bool is set you store your character current location at that frame, and then next frame you move it to the same location, so no multiplication involved.
If this get rid of the glitches, then you can take it from there and move him every tick at that location if he doesn’t move, or as starting location for the next movement.
Also I do believe that the UCharacterMovementComponent that comes with your default character also give you the option to switch between several moving mode, like “fly”, “crouch”, “swim” and there is also a “Custom”.
So maybe you can switch to Custom movement mode while on top of a moving platform and revert back to “Walk” while not.

Though I don’t know if this Custom thing can be set in blueprint or not, never done this stuff :stuck_out_tongue:

Hi ムリですよ](User Profile - Unreal Engine Forums), I tried your UpdateBaseMovement idea.It worked.The character didn’t move with the floor and fell off the edge.
Thanks.:slight_smile:

Thats nice, thankyou for that information never thought of tackling it that way

Wait, with “I tried your UpdateBaseMovement idea” you mean the C++ idea about inheriting from the UCharacterMovementComponent and overriding the UpdateBaseMovement method?!
I actually attempted that too out of curiousity, but I failed to tell the character to use my movement component instead of the default UCharacterMovementComponent it gets when it is constructed.

If you managed to make it work, can you show me how did you substituted his default UCharacterMovementComponent for yours? :stuck_out_tongue:

Nevermind, I had a small error in the code, now the C++ version works as well :slight_smile:

Sorry for not replying you for so long.I didn’t check out message recently.
you can find how to change character movement component in here