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 ムリですよ](https://forums.unrealengine.com/member/69332-ムリですよ), 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

For anyone wondering there is a very simple solution. I am using Unreal 5.1 and in my character blueprint, under the Character Movement component, I have Default Land Movement Mode set to Walking. Just set it to None.
However, this will prevent you from falling. If this is a concern to you, an even better approach would be to lock movement to a specific plane.
In my case I wanted to move the floor along X and not allow the character to slide with the floor. What I did was navigate to Character Movement component again, on the right under details → Planar Movement: set Constrain to Plane to true and Plane Constraint Axis Setting to X. This worked perfectly as the character could not move along X so he couldn’t slide with the floor.
2023-05-10 17_44_39-Window
2023-05-10 17_44_18-Window

I think this is the right way to obtain the result we want.
The implementation of my overriden UpdateBasedMovement() method is:

void UMyCharacterMovementComponent::UpdateBasedMovement(float DeltaSeconds)
{
	const IMyInterface* CastedObject = Cast<IMyInterface>(CharacterOwner->GetMovementBase());
	if (CastedObject && CastedObject->IgnoreBasedMovementInfo())
	{
		return;
	}

	Super::UpdateBasedMovement(DeltaSeconds);
}

Obviously IMyInterface is an interface class where the method bool IgnoreBasedMovementInfo() was declared.
An extend class of UBoxComponent implements that interface and when IgnoreBasedMovementInfo() returns true then the character stop to follow the movement of the platform he steps on.
The result I obtained is:
giphy

1 Like