Hi RICC,
I'm struggling with implementing moving platforms & I'm hoping maybe someone around here has some insight.
I basically define the behavior of a "Moving Platform" with:
-MovementComponent
-SolidSurfaceComponent with 4 surfaces
^^those two are in the static data^^
-RenderComponent
-SpriteComponent
-DynamicCollisionComponent
-HitReactionComponent
-SimplePatrolComponent
and a new component
-MovingPlatformComponent
The behavior is basically that the the whole moving platform has a vulnerability volume of type DEPRESS over the surface of the platform (my player characters have a DEPRESS attack volume near their feet). When the player stands on the platform the HitReactionComponent is triggered for the DEPRESS action. I modified the HitReactionComponent to track multiple attackers (as I have 2 characters at once, both of which could be standing on the moving platform). The update method of the MovingPlatformComponent fetches the HitReactionComponent, fetches the attackers from that, and adds to their position by the delta position of the parent object (the platform). This works fine for platforms moving left/right and even down, but I have an issue with a platform moving up where the player characters are "popping" up a tiny bit then falling to the platform again as it moves upward. I need them to stay on the platform and smoothly move upward with it.
Here is the update method in the MovingPlatformComponent:
public void update(float timeDelta, BaseObject parent)
{
GameObject parentObject = (GameObject) parent;
if (parentObject.getCurrentAction() == ActionType.HIT_REACT && parentObject.lastReceivedHitType == CollisionParameters.HitType.DEPRESS)
{
HitReactionComponent hitReact = parentObject.findByClass(HitReactionComponent.class);
if (hitReact != null)
{
Set<GameObject> attackers = hitReact.getLastAttackers();
if (attackers != null && attackers.size() > 0) {
for (GameObject attacker : attackers) {
if (attacker != null) {
float positionDeltaX = parentObject.getPosition().x - this.mLastPosX;
float positionDeltaY = parentObject.getPosition().y - this.mLastPosY;
attacker.getPosition().x += positionDeltaX;
attacker.getPosition().y += positionDeltaY;
}
}
}
}
}
this.mLastPosX = parentObject.getPosition().x;
this.mLastPosY = parentObject.getPosition().y;
}
let me know if any other relevant code would help and I'll post it.
Thanks!
Eric