- Basic first person example
- Added input for “Slav Squat” action
- Added Crouch and UnCrouch nodes to be executed by “Slav Squat” action
- Added an “OnStartCrouch” event handler that takes halfHeightAdjust and adds that to a fps camera’s relative location Z
I expect this to keep camera world location the same as before I toggle crouching on (to add a timeline later and animate smooth crouching). What actually happens is that camera moves down with fps character because of “crouch maintains base location” and addRelativeLocation simply does not do what it supposed to do. The same thing is done for actor’s mesh inside Character.cpp:
void ACharacter::OnStartCrouch( float HeightAdjust, float ScaledHeightAdjust )
const ACharacter* DefaultChar = GetDefault<ACharacter>(GetClass());
if (Mesh && DefaultChar->Mesh)
// this adjusts mesh location to keep it's world location the same as before crouching
Mesh->RelativeLocation.Z = DefaultChar->Mesh->RelativeLocation.Z + HeightAdjust;
BaseTranslationOffset.Z = Mesh->RelativeLocation.Z;
BaseTranslationOffset.Z = DefaultChar->BaseTranslationOffset.Z + HeightAdjust;
// this calls my blueprint's "OnStartCrouch" handler where I try to do the same for the camera
The mesh is properly moved up relatively to actor’s center by .cpp code, but my blueprint counterpart for the camera won’t affect camera’s relative location for some reason. It does work if I sum halfHeightAdjust with some other value, or if I set either delta location x or y to some non-zero value – this way the camera maintains it’s world location when crouching with a difference of value(s) I added. My question is, how can I implement this properly without added values and any sort of dirty hackery? Is something needed to force a component’s relative location change? Or are there any proper ways/workarounds to make this work?
p.s. I know a camera can be reparented to be a character’s inherited mesh component child and it WILL maintain it’s world location along with mesh when crouching, but then there is an identical need to adjust mesh’s relative location when attempting to crouch during jumping (falling movement state) and again, it does not work. Let me explain this case: a falling movement mode sets “crouch maintains base location” to false, so crouching while jumping DOES NOT adjust an actor’s location. ACharacter::OnStartCrouch, however, ignores “crouch maintains base location” and always adjusts mesh location (is it an actual bug?) so the mesh teleports up by halfHeightAdjust value. If I attempt to cancel out this adjustment done by c++ code in OnStartCrouch with my blueprint’s OnStartCrouch event handler by calling addRelativeLocation with a negated halfHeightAdjust, nothing happens unless I add some value to any axis, so the question about why this happens and how to fight it still remains.