Hello,
I am trying to implement crouching in my 2DSideScroller example project (C++).
It is an infinite stroller (Player always moving rightwards), and when the player presses down, the player will crouch for one second and then stand up again.
Code for crouching:
GetCapsuleComponent()->SetCapsuleHalfHeight(normalCapsuleHalfHeight / 2.f);
GetCapsuleComponent()->AddWorldOffset
(FVector(0.f, 0.f, - (normalCapsuleHalfHeight / 4.f)));
GetCameraBoom()->AddLocalOffset(FVector(0.f, 0.f, normalCapsuleHalfHeight / 2.f));
Sketch of what’s happening;
And this works perfectly fine. After 1 second, when the timer has expired, I just reverse it.
GetCapsuleComponent()->SetCapsuleHalfHeight(normalCapsuleHalfHeight);
GetCameraBoom()->AddLocalOffset(FVector(0.f, 0.f, -(normalCapsuleHalfHeight / 2.f)));
GetCapsuleComponent()->AddWorldOffset
(FVector(0.f, 0.f, normalCapsuleHalfHeight / 4.f));
However, I’m guessing that a frame is being rendered in between those three operations, and this results in an ugly ‘camera jump’. The camera is supposed to be stationary during a crouch/roll…so how is this usually done?
I never get the ugly frame when rolling, only when standing up again, any ideas?
EDIT: The camera jitter still happens even if I translate the capsule upwards before restoring it to it’s original size