How to move a platform with a player pawn ball on it?

How do you move a platform under a physics-simulated (player pawn) ball, in a stable and FPS-independent way? If I simply use linear interpolation and set location calls without physics enabled, the platform causes physics issues with the ball, such as causing it to bounce erratically while on the platform.

Simulating physics for the platform, and setting linear velocity to move it, is more stable on the physics and movement front, but comes with its own issues. When I use this method, I lose the specific control over position and timing that I had with the first (kinematic) method.

So - is there a method or combination of methods that can I can use to move the platform in a way that is both physically stable and with precise timing control?

I was having this issue in UE3 with moving platforms + rolling balls

I ended up writing code to try and propel the ball along with the move direction of the platform (in ue3 unrealscript)

Really you should probably take a good look at how Epic handles this for Characters, look up all the info on Base, set Base, basing,

You will have to write your own code for handling a physics simulating character / static mesh.

Character.h


/** Sets the MovementBase used by CharacterMovement walking movement. */
virtual void SetBase(UPrimitiveComponent* NewBase, bool bNotifyActor=true);

/** Component we are based on */
	UPROPERTY()
	class UPrimitiveComponent* MovementBase;

	/** Desired translation offset of mesh. */
	UPROPERTY()
	FVector BaseTranslationOffset;

	/** Event called after actor's base changes (if SetBase was requested to notify us with bNotifyPawn). */
	virtual void BaseChange();

	// Always called immediately after properties are received from the remote.
	virtual void PostNetReceiveBase();

I’m already doing a trace directly downwards to test if my physics-based character can jump, so its easy to get a reference to whatever object the player is standing on. I’m also already handling gravity manually. I went into Character.cpp and copy-pasted GetMovementBaseVelocity and GetMovementBaseTangentialVelocity into my Pawn’s class.

Then in Tick, where I handle gravity forces, I set it up like this:



CheckGrounded(); // does a trace and sets movementBase to the object the player is standing on

FVector gravity = FVector(0, 0, -980.f);
FVector baseVelocity = GetMovementBaseVelocity(movementBase);
FVector baseTangentialVelocity = GetMovementBaseTangentialVelocity(movementBase, GetActorLocation());

// AddImpulse with DeltaTime factored in seems to give better results than AddForce without DeltaTime
PhysMesh->AddImpulse((gravity + baseVelocity + baseTangentialVelocity) * PhysMesh->GetMass() * DeltaTime);


This seems to really improve things - not just in terms of moving platform glitches, but it’s just generally more fun and feels a lot better. Is this technique essentially what you’re describing, or am I missing something important about character bases?