I have a round world. So I’m converting the character movement component to allow for this. I use
FTransform compToWorldTrans = CharacterOwner->GetCapsuleComponent()->GetComponentTransform();
FVector rotatedVector = compToWorldTrans.InverseTransformVectorNoScale(VectorToConvert);
return rotatedVector;
to give me the unrotated vector to compare against throughout the CMP. Alternatively I use
FTransform compToWorldTrans = CharacterOwner->GetCapsuleComponent()->GetComponentTransform();
FVector rotatedVector = compToWorldTrans.TransformVectorNoScale(VectorToConvert);
return rotatedVector;
to give me the rotated vector for gravity and similar logic. On my character class on the tick function I adjust the characters control rotation so that the down vector of the capsule always points toward the planet center like so
FRotator addInRot = FRotator(0, mouseX, 0);
FRotator correctRot = FRotationMatrix::MakeFromZX(GetCapsuleComponent()->GetComponentLocation(), GetCapsuleComponent()->GetForwardVector()).Rotator();
FQuat testQuat = correctRot.Quaternion() * addInRot.Quaternion();
Controller->SetControlRotation(testQuat.Rotator());
Yet when I move my character around in the world I can see the velocity vector and acceleration vector start to diverge from the control rotation forward vector. You can see this in the screen shot. The screen grab shows the character moving “forward” or pressing the “w” key. The velocity and acceleration should point in the same vector as the control rotation. Now there’s a lot inside the CMP so I could have missed something but I’m trying to narrow down where this is occurring at. Is it a result of the control rotation in my character class being incorrect? Am I adding those rotations together the wrong way? The blue line appears to be correct to me. So I’m guessing it’s somewhere in the CMP, but for the life of me I cannot figure out where.