Help me make a reactive capsule pushing system

In ways this thread / question will kind of be a spiritual sequel to the thread I did awhile back on the moving wall.

To sum that thread up, the basic gist is that if any platforms push you HORIZONTALLY it causes the player to “jerk” and not be pushed smoothly, this is because of the SHAPE of the capsule component, the penetrating wall or platform having to reach the exact center of the bottom of the player’s capsule and then the player essentially teleporting ahead of the moving wall creating a very herky jerky effect.

I finally got the effect I was after, but then I started thinking about how could one make a reactive system. a system where the player’s capsule would receive an offset directly in the horizontal direction and at the exact speed received.

I welcome any opinions and ideas about this topic. I’m not sure how to go about this strategy but I do think it could work. I imagine one would have to have a way to detect what angle collision is occurring an act accordingly. Since the problem is only with horizontal collisions that eliminates Z entirely. X - and +, and Y - and + would be all that is needed.

Thanks.

1 Like

Been awhile since I posted. I will try to talk more about this concept tonight. As many other threads have pointed out, the problem with moving platforms and UE4 is HORIZONTAL moving platforms, while vertical moving platforms seem to be fine. This points again to the shape of the capsule component, being it is rounded at the center.

When a horizontal moving platform pushes against the players capsule it seems it doesn’t register until the horizontally moving platform reaches the exact center of the capsule, at which point the computer instantly warps the capsule to outside the platform…result? a herky jerky horizontal movement, not a smooth movement one would probably expect or want.

I have an idea how to accomplish this, but need more insight from any of you math UE4 wizards out there.

Here is an overhead picture of this concept

Imagine 4 very skinny box collisions set up around the player. These can correspond with North, South, East, and West. If ANY “moving” thing penetrates / overlaps these boxes (horizontal moving wall?), the players capsule receives a corresponding push in said direction of the exact velocity of the object.

SO then, how exactly to check the velocity of an object / actor overlapping each box?

Thanks for any ideas or opinions.

bump bump

Didn’t read the other thread, but I know the general problem. The simple solution is just to add actor offset to the character; you can do this safely to the character and other physics objects.

This is something I slapped together quickly. It is not the full solution, just an example of how to push the character. It has an obvious problem seen in the video where the character can’t move side-to-side while on the wall.


The wall is set to “OverlapOnlyPawn”.

3 Likes

Thank you, will check this out later when I have more time.

First off thanks for taking the time to make that video and reply.

Ok, I have a few questions here to get started. I assume the diagram I’m looking at is an actor BP for the wall itself (dragged into the world) as the add actor local offset has just “self” as the target.

For me, I’m having to use “Add Actor WORLD offset” in order to get any movement, also, I’m having to use “float + float” node instead of the multiplication, or just plug the wall speed get variable directly into the split struct pin Y of the addactorworldoffset node.

Again its an actor BP for the wall itself dragged into the world. Not sure why its not letting me use the local offset as you did.

But for testing purposes I already had the wall moving at a fixed rate (like 2 in the Y).

Tell you what, before I go further I will just show you what I had before for simple testing purposes. In this video, you will see three moving walls. “Movers” as I called them in this, they are all moving at a fixed speed of 1.

Mover 1 is coming from the background straight toward the camera (-1 in the X).

Mover 2 is going straight up in the aIr (1 in the Z).

Mover 3 is going from left to right (1 in the Y)

In the first 50 seconds of the video, I show how that UE4 reacts to HORIZONTALLY moving platforms by default. You can clearly see the herky jerky effect @ 41-50 seconds of the video. Then I show what happens when I connect two EXEC wires completing circuits that have box collision and capsule pushing elements / logic.

So I’m thinking of how to add your ideas to this and go forward. Like you said these are not complete solution but demonstration of concepts if anything.

When I say reactive, I mean to somehow be able to gauge and match speed of ANY thing that is MOVING and OVERLAPS to simulate what perhaps the engine should be able to do out of the box.

So the solution is actually pretty simple:

All we are saying here is if the wall hits something on the way to its target location, move the wall and the hit object the rest of the way. The delta (the vector to get the hit location to the target location) is the target location minus the hit location. The wall is set to only collide with pawns, which is why I don’t check what the hit actor is (but it works on simulated objects, too).

I realized that using overlaps instead of collisions/sweeps would result in the overlap being missed if the wall moves too fast, so using the sweep ensures the entire path is tested for collisions. The numbers above the walls are the speeds.

Once again thx for trying to help me and taking the time to make this. I hope you don’t mind me asking questions. I’m here to learn and help others when and where I can.

Can you tell me what this node is? It doesn’t seem to appear as a typical break hit result??? How do I get it? That seems to be the only node on that diagram I couldn’t get.

You just split the pin on the hit variable (right click the pin → “Split Struct Pin”). You can do that on any node, I just used a variable here so I can get in in one pic.
image

Oh wow, that is all that was, a split struct pin, I did not see that coming.

I created a new project just for your code. I tried to leave the player in the default third person character room / box.

I made an actor BP for the wall, added a cube in details and scaled it accordingly, placed it in the world. I get no movement from the wall at all with the above code.

Please show what I’m doing wrong, thanks.

bump bump

bump bump

No one else have any issues with horizontal moving walls / platforms???

That’s weird. I thought it might be it colliding with something else that’s stopping it, but I tested that on mine (using BlockAllDynamic and having the wall in the ground), and that didn’t stop it. The only thing I can think of that would cause this is your wall speed being 0. Try setting TargetLocation to (0,0,0) (or anything) and see if it moves to that location.

Make sure your static mesh is the root component and is set to moveable (you should get a warning if not).

It is the root and is set to movable.

The wall speed is currently set to 2.

For some reason I had to set wall speed to 100-200 to finally get movement.

Target Location - If I add some / take some away in the Y (along with wall speed way up like 100 or 200) I can get some movement however…I get a weird pass through from the wall. I tried collision on block all and block all dynamic. Its not a clean pass through like an overlap all setting for example, as if there is a small movement there or mess with the camera a second.

Any other ideas? thx

Yeah, mine in the video is set to 100 & 800, so that’s correct behavior. The reason is that when you multiply by delta seconds, the speed is in units-per-second (which is cm-per-second in Unreal). The reason for multiplying by delta seconds is that the speed the wall moves becomes independent of framerate; if not, the speed the wall moves will vary based on the framerate.

Using block all was just a test to see if that was the culprit (though, you should still get movement regardless since the AddActorWorldOffset part has sweep disabled). In my video, I have the collision set to only collide with pawns (there’s no preset for this, you just set the mode to custom and set all to ignore except for pawn).

You should now have a working wall that should just move & push the player. If not, I don’t know what else could be the problem.

midgunner66 “Yeah, mine in the video is set to 100 & 800, so that’s correct behavior.”

Ok so that is not too uncommon then, good to know.

“The reason is that when you multiply by delta seconds, the speed is in units-per-second (which is cm-per-second in Unreal). The reason for multiplying by delta seconds is that the speed the wall moves becomes independent of framerate; if not, the speed the wall moves will vary based on the framerate.”

Yeah I like the thought of that, movement speed that is independent of frame rate. Many modern PC games are locking players to 60 HZ when the systems are clearly capable of much more then that.

I set the target location to Y -2.0 and it has a decent left to right movement speed.

I finally got your code to work! Not sure what I did differently.

I made a video below of your code working.

But as you said before, this is a proof of concept, not a complete solution, so I do not think we are done here.

And while this is working as a demonstration, I’m not sure I totally understand how it does. The magic here must be in that hit result, I don’t get how it is referencing or accessing the third person character to move the capsule, when this code is all in a separate actor BP, and no cast to get access to the third person character.

I appreciate the help, thx again.

2 Likes

Yeah, there’s other problems. Like, if you have it push a physics object, and that physics object pushes against the character, the physics object will get squeezed between the wall and the character.

The actor it hits doesn’t matter because all we’re doing is setting the location of the actor, which can be done on all actors. Since the collision is set to pawn only, you don’t need to cast because we will only hit pawns, which is what a character is. It works on all actors, I only set it to pawn to stop warnings when it hit the walls.

No problem, it is kinda annoying that this doesn’t work already.

I noticed that the moving wall had the ability to push the player completely through the wall of the default third person character template. Any ideas how to fix that?

Ok

Yes, it is, I can’t believe this issue has not been solved yet. Does UE5 still have this problem?

In the meantime, I’m starting to wonder if this issue has to be solved on a per case basis with every moving platform in a level, in which case the speed of the moving wall will always be known for each platform. Which goes against my idea of creating a system that can compensate for anything moving, using only the third person character BP.

You can stop the wall by getting if the hit actor hits something during the move. This is just a thrown together example:

But this will stop the wall if the player hits anything, so you’d probably want to do more, like check what the player hit. But, assuming the wall is meant to crush the player, you can kill the player, too. You also aren’t limited to a sweep, you can use a trace as well, or anything else.

Haven’t tested, but I’m sure it does.

Yeah. But hit events fire for both actors that collide, so maybe this can be handled from the character bp instead. Edit: Did a quick test, and you can do this. I just have the wall bp only move with sweep on, and have the character BP handle the pushing part if it was hit.


The only problem is the wall randomly stops & starts sometimes. I don’t know why (think it may be that the hit isn’t firing every time for the character), but it should be easy to fix. Also, this does still use a target location variable, which means the wall actor has to have one for this to work; though, you can get it from any actor through an interface. Shouldn’t be a problem, but if it is, maybe using the trace end in the hit result or the wall’s normal can remove the need for it.