Moving platforms that move the player character

Hi! I’m trying to make a moving platform that moves the player’s rigidbody with it, some good examples come from the moving platforms in Portal/Portal 2 by Valve. I am not sure how I would do it, here is my project!
https://playcanvas.com/project/978072/overview/fps-project

EDIT: The object I am trying to move is called “tweened”, it would move back and forth between two positions, the origin position, and the border of the base platform.

Maybe this thread can help: [SOLVED] Glitchy elevator physics

All I am seeing in that thread is that they have a problem with upward movement that is due to frame issues and contact, which shouldn’t be a problem with my project, but what I’m talking about is horizontal movement. Let’s say the platform is still, and the player gets on it. It moves to take them across a gap, and that doesn’t carry the player properly, moving them for a bit but dropping them if they don’t move with it.

Hi @Cryptonaph! Maybe the topic below can help you.

This does somewhat help, however whenever I am on the moving platform, the character bounces up and down a bit and it causes them to fall off, which confuses me because if it is applying the velocity that the platform has to the player, why does the player not stay in the same spot while bouncing on it?

EDIT: I think it’s worth mentioning that this happens because the moving platform has a restitution of 1 so the player would completely stick to it.

So I did some messing around, found out it was a sneaky line that got past me, so I fixed that. The player now stays on the platform, but they slide from side to side on the platform, can’t move properly, and they can’t jump. Movement is extremely slow, I have tried a ton but can’t figure this out for the life of me. The exact thing I am aiming for is for the player to essentially be glued to that spot on the platform so they won’t slide around when it moves, but still be able to move themselves. I think a good example would be how ROBLOX does their physics, if you are standing on a part, you get moved with it, staying in the same position relative to the moving part.

If the workarounds from the other topic not work for you, I’m afraid there is no way to achieve the desired result.

So I looked at the post linked before again, and I remembered that this was posted on that thread. How would one go about simulating physics relative to an entity? I’m specifically looking at this sentence.

This might be hard to implement, though, as you’d need to manage moving the player from world to local grid and back.
Because I’m not sure how you would calculate it on a local grid instead of a world grid.

Did the post below with the example project not help you?

Sadly no, what I’m going for is kind of a more realistic look. Like, for example, if you are standing on the back of a truck and it’s moving forward, you would stay in the same spot relative to the truck. That is what I am aiming for. Another example is the synchronised physics grids that Star Citizen uses.

EDIT: If needed I can provide a visual example.

That’s exactly what is done in the example project?

In the example project the player slides back and forth whenever it moves, which looks weird.

That’s because the platform moves back and forth too. Imagine what happens if a truck start to move when you are standing on it…

Hm, true, is there any way I could remove that happening though?

As far I can see, line 31 of platform.js moves the platform, so you need to replace this line with your own movement method.

Well, I’m fine with how the platform itself moves currently, but how would I make it keep the player on the same spot on that platform?

Is the player still sliding off, when the platform moves in one direction?

No, they don’t slide off, but they stop like right near the edge. I want them to stay in the same spot local to the platform.

Thinking about a solution myself is using a downwards raycast and use the hit position of it to keep the player on the right position, but I’m not sure what the result will be when the player moves.

1 Like

Yeah, this all has me stumped, I’m not sure how to get my thing to work. I do know of a good example for what I need. This video shows how the physics in Titanfall 2 work, and how moving platforms work. And while yes, it very clearly is a video about how players can manipulate them, that is something I actually want in my game. I already left an advanced technique in the wall jumping that can be used.

1 Like