I have an issue with moving platforms, basically, the player position is reset/updated when the player is on the moving platform. Please see the playground link below.
I basically need the player to stick to the moving platform and still be able to move the player with the keyboard while the platform is moving.
Thanks for the response, the code in the playground is the simplified version of my game code so I think the solutions above might not work. What I’m trying to achieve is in this video ( https://www.youtube.com/watch?v=rO19dA2jksk )
I have the code working but the player is repositioned a few seconds after jumping on the platform. Please see the video below.
I completely misunderstood your original question. I thought you want to move the box by user on the moving floor and don’t wan’t the box to get out.
My point is still the same. You already uses a physics engine, you can avoid directly modifying the positions of objects like floor. Try to use a force to push the floor left and right. See this PG:
What if you do player.parent = floor instead of setParent?
Anyways I’d think updating the players position per the moving blocks velocity * the engine delta time * 0.001 if it’s grounded to the platform would be better.
I get back in town today, but won’t be able to look till tomorrow
Still stuck on this and any help will be appreciated. @Pryme8 I tried your suggestion and still no luck. What could be making the player position reset? (based on the video)
Also, can anyone point me in the direction of a moving platform with a player on it done on BJS if there is any?
@Pryme8 So, I investigated a little bit more and I am not sure where the issue is. I used a cube to test and still got the same result. (see video below)
Regarding your suggestion above ( Anyways I’d think updating the players position per the moving blocks velocity * the engine delta time * 0.001 if it’s grounded to the platform would be better. )
Could you please help me out with a playground code? I need the help.
Another thing, if I keep running around on the platform, it works. (see video below) Maybe that might help.
Actually after reading your requirements and seeing how the PG that I just modified would not meet your needs I went back and made some fixes.
This would be a more “correct” answer
Basically you take the platforms current position and then subtract its last position, then if the player is grounded add that in place to the player position.
This should suit all your conditions let me know if there is more I did not think of for you.
Sorry it took so long to get this simple of an answer to you, it was just hard to make and example on my phone.
@Pryme8 Thank you for the assistance, worked like a charm!. It was the second solution you suggested. Although, I noticed some jumpy behaviour when using [ scene.registerBeforeRender(() ] but works well in [ renderLoop ] function. Not sure why yet but will report here if I locate the issue. See videos below.