Download

Character gravity dependent on frame rate?

I’m making a first person game primarily in C++ where the player has multiple ways of launching upwards against gravity. So far, I’ve implemented jumping with Jump() and AddImpulse(), as well as created a block actor which launches the player upwards after being stepped on.

Jump: (JumpUpdate() is an empty functon)


void APlayerCharacter2::OnJumpPressed() { if (GetCharacterMovement()->MovementMode == EMovementMode::MOVE_Walking) { GetCharacterMovement()->AddImpulse(FVector(0, 0, BaseJumpSpeed), true); GetWorldTimerManager().SetTimer(JumpTimer, this, &APlayerCharacter2::JumpUpdate, 1.0, false); } //Jump(); does the exact same thing here }

The SetTimer() code for the block actor is pretty much the same, and I use OnMovementModeChanged() to clear the timer after landing. But with both modes of vertical travel, I noticed differences in airtime when I changed the “Fixed Frame Rate” in project settings. From jumping straight up and down on the same level ground, these are the GetTimerElapsed() results at different frame rates: [TABLE]

		30
		0.5333
	
	
		60
		0.5667
	
	
		120
		0.5883
	
	
		144
		0.5903

And from slowly walking over the “floater” blocks (block actors that launch the character upwards): [TABLE]

		30
		1.1
	
	
		60
		1.117
	
	
		120
		1.142
	
	
		144
		1.152

Is character gravity dependent on frame rate? When I tried dividing the GetCharacterMovement()->GravityScale by DeltaTime in Tick(), 30 FPS jumping sent the character flying and 144 FPS jumping didn’t get half a second of airtime. Has anyone noticed anything similar? How can I fix this?