Moving Platform Jittering

I want to be able to have moving platforms for some tests I’m working on, but I can’t see to get this right.

All I want is for an object on top of a moving platform to move with the platform (however the object still needs to be able to move on the platform).

Right now, any object I put on top of the moving platform moves with the platform… but not flawlessly. There are small jitters when the object is moving down (it seems like the object is moving into the platform instead of just staying on top of it). When moving up, the object is slightly above the platform.
I’m thinking this is more a programming error than anything.


Basic Setup:
- Platform moves with "vel" velocity (per frame)
- If platforms collides with anything:
     - hit_obj.applyMovement(vel)

This is everything I do. You can find this in the platform.py, under the Movement class, under the move function.

I don’t know what I’m doing wrong.

Ideas?

PlatformMovingTest.zip (213 KB)

Hello! You can try physics character. Otherwise, you can play with actuators set/remove parent… Maybe there is a better solution…

I think the jittering during downward movement results from the difference between “applyMovement” and “setLinearVelocity” for a dynamic object. I don’t know what exactly setMovement does to a dynamic object. Anyway, if you replace the former with the latter in your code, the jittering will disappear. BUT: I don’t know how to correctly calculate the equivalent LinearVelocity for a given movement.

The problem with using the physics character is that already so much is based on a template, it kind of interferes with the way I’ve built my physics “character”.

Parenting doesn’t really work because children can’t when parented.

applyMovement quite changes the world position of the object. It works like the loc motion actuator. it’d be cool to find a way use linear velocity but I’m not sure how. What I do know is that linear velocity is BU per second while movement is BU per frame.

Alright, so I’ve come up with a pretty fun solution.

I would like to know if you guys find any glitches with it because I’m actually not too sure if it works in all case.

Anyways, instead of making the platform static, I actually made it dynamic and added a Float component. The Float component adjusts the forces acting on the platform so it’s always moving with the correct speed in the correct direction. It also takes into account the amount of objects on top of it (kind of, it won’t work if you stack boxes since it only checks for collisions). I also always assume all objects on top of the platform are of mass 1.

Please check it out and tell me what you think, this seems to be my best solution so far…

PlatformMovingTest2.zip (214 KB)

As always, if there are better solutions please say so (:

(I’m also not sure if “Float” is a good name for what the component does, I have to put more thought into it I guess)

So ultimately, I decided to actually not go with the force based platform movement because it seemed to overcomplicate something that is suppose to be simple.

All I’m trying to do is make an object (that can move on its own) on top of a platform move with the platform (without the jittering when moving down).

So back to my first post, how do I fix the jittering?

If you’re talking about the object jumping when a platform is moving up and down, I believe this is actually the results of a physics regression introduced late in the 2.6x series (the last time the Bullet library for the BGE was touched).

There’s an animation optimization feature in the world panel you can uncheck to reduce the jumping, but it won’t remove it completely. In any manner, allowing for smooth control on moving platforms is harder than it used to be.

I guess I’ll just have to live with it… Agh.

I can’t seem to find that option in the world panel… Hmm…
What I did notice though was that increasing the physics substeps helps a bit (instead of 1 substeps, 2 substeps). It’s a good thing my current project isn’t going to be super heavy on physics :stuck_out_tongue:

You could make the moving platform a ghost, and then use raycasts to move the character onto and with the platform.

You should also be able to negate the linear velocity increase itself if you so wanted (i.e. have the platform move the “carrying” object up or down and then set its linear velocity on the Z axis to 0). If you do this only when the linear velocity on the Z axis is below a certain threshold, it would lock the player in place but allow him to jump.

EDIT: Tried that second suggestion. It doesn’t stop the jittering. Rays might be your best friend for this.

EDIT 2: This works for that second suggestion:


for i in self.gobj.n_sensors["Collision"].hit_list():
    i.applyMovement(self.gobj.vel)
    i.worldLinearVelocity.z = 0  # New lines are these two; stops the other object from falling
    i.applyForce([0, 0, 9.8])  # Should be the gravity value for the worl

Note that you probably want to use another object to check for collision so that only objects that are on the top of a platform are moved along with it, not just objects that touch it from all sides.

Hmmm, works to work nicely, I hadn’t tried setting the linear velocity on the z to be zero because I thought it would prevent jumping (with player input). It works! (a little glitchy with my real setup but I could probably buff those out fairly easily).

As for the collisions, in my actual setup I check for specific properties (instances and actual properties in some cases), which works just as well I guess.

I’m also debating whether or not I would make the player move it self on the platform over the platform moving the player. Even though the latter makes much more sense, the former might be easier coding wise.

Anyways, thanks!