Character Control on vertically moving platforms

Hello,

I’m currently having an issue in my game when I’m standing on a platform that moves vertically.

For the horizontal ones, I just add on my CharacterControl.setWalkDirection the same movement as for the platform, it works fine.

But when the platform is moving up, my character is stuck to the knees and sometimes event falls through it.
That’s without adding anything on the CharacterControl.setWalkDirection.
If I try to add the same movement as for the horizontal platform, it’s event worse, the character get stuck to the hips.

It’s quite difficult to extract the code for that since it’s in the middle of thousands of lines but it’s something like that:

The moving of the platform:
[java]
List<Node> toDeleteMovingBlocks = new ArrayList<Node>();
public void manageMovingBlocks(float tpf) {
for ( Node movingBlock : movingBlocks ) {

		T3DBlock block = (T3DBlock) movingBlock.getUserData("T3DBlock");
		
		if ( block.moveDirection == Const.FRONT_SIDE ) {
			movingBlock.move(0,0,5f*tpf);
		} else if (  block.moveDirection == Const.BACK_SIDE ) {
			movingBlock.move(0,0,-5f*tpf);
		} else if (  block.moveDirection == Const.LEFT_SIDE ) {
			movingBlock.move(-5f*tpf,0,0);
		} else if (  block.moveDirection == Const.RIGHT_SIDE ) {
			movingBlock.move(5f*tpf,0,0);
		} else if (  block.moveDirection == Const.TOP_SIDE ) {
			movingBlock.move(0,5f*tpf,0);
		} else if (  block.moveDirection == Const.BOTTOM_SIDE ) {
			movingBlock.move(0,-5f*tpf,0);
		}
		block.blockControl.setPhysicsLocation(movingBlock.getWorldTranslation());
		block.moveRemaining = block.moveRemaining -(5f*tpf);
		
		if( block.moveRemaining &lt;=0 ) {
			toDeleteMovingBlocks.add(movingBlock);
			
		}
	}
	if( toDeleteMovingBlocks.size()&gt;0) {
    	for ( Node deleteBlock : toDeleteMovingBlocks ) {
    		movingBlocks.remove(deleteBlock);
    	}
    	toDeleteMovingBlocks.clear();
	}
}

[/java]

The procedure that creates the Vector3f to add the the setWalkDirection:

[java]
public Vector3f getAutoMoveVector(Vector3f persoPosition, float tpf) {
for ( Node movingBlock : movingBlocks ) {

    	colResult = GeometryUtils.launchRay(movingBlock, persoPosition, new Vector3f(0,-1,0));
    	// Only apply forces for blocks close enough bellow character
    	if ( colResult != null &amp;&amp; colResult.getDistance() &lt; 3f ) {
    		
    		T3DBlock b = (T3DBlock) movingBlock.getUserData("T3DBlock");
    		
			if ( b.moveDirection == Const.FRONT_SIDE ) {
				return new Vector3f(0,0,5f*tpf);
			} else if (  b.moveDirection == Const.BACK_SIDE ) {
				return new Vector3f(0,0,-5f*tpf);
			} else if (  b.moveDirection == Const.LEFT_SIDE ) {
				return new Vector3f(-5f*tpf,0,0);
			} else if (  b.moveDirection == Const.RIGHT_SIDE ) {
				return new Vector3f(5f*tpf,0,0);
			} 
			// Worse with that ! 
			/*else if (  b.moveDirection == Const.TOP_SIDE ) {
				return new Vector3f(0,5f*tpf,0);
			} else if (  b.moveDirection == Const.BOTTOM_SIDE ) {
				return new Vector3f(0,-5f*tpf,0);
			}*/

			
    	}        
    }
    return null;
}

[/java]

And finally how it’s added :

[java]
// Computation of the real movement before in the walkDirection variable.

	Vector3f autoMoveVector = getAutoMoveVector(persoSprite.getTileSprite().getRootLayer().layerNode.getWorldTranslation(),tpf);
	if( autoMoveVector != null ) {
		walkDirection.addLocal(autoMoveVector);
	}

	characterControl.setWalkDirection(walkDirection);

[/java]

Any idea on how I could improve that? Horizontal elevators are not very sexy :wink:

Thanks in advance !

I’d just attach the character to the elevator and be done with it, why mess with the physics? Or make a local physics space for the elevator.

Okay I’ll try that, remove from rootNode and attach to the elevator when it’s moving.

Thanks :wink: