I am a bit new to coding in C++ and i’ve run into a problem as i am mostly doing things in Blueprint.
I’m making Airships and other vehicles that need to have free character movement while in use so i am attaching the character to an airship (pawn) when the character enters a specific volume so i can have movement parented and localized to the airship’s frame of reference, this part mostly works, but there is an issue with the CharacterMovement component that makes the Character move at 2x the speed of the airship when in flight, this seems due to the engine compensating for pawns standing on top of moving objects, when attached to a moving pawn (which obivously removes the need for this compensation) the engine over-compensates instead.
I was wondering how i should go about fixing this, i’ve done enough reading to understand that i need to make a custom CharacterMovement component but i am unfamiliar to how the .h and .cpp structure works or what part of the code to overwrite or how.
Ideally i’d like to add an exception for the normal rule so that when the Character is attached to something it should not compensate for base movement.
Any help on this issue would be greatly appreciated!
I’ve seen that page but the problem is that it doesn’t actaully tell me anything useful for either solving my issue or understanding the .h and .cpp structure.
It’s a more basic problem really, i have this issue with most new coding languages before i can get into it hard-core, i need to really understand the quirks of a langauge and why it is structured in a certain way and what relation that has to what it’s doing before i can do anything useful in it myself, before then I’m logic blocked
As to the 2x speed, try it yourself, you’ll get the exact same problem. Attach a character to a moving pawn, it would have to be a platform of some kind obivously, and you’ll see what i mean.
The reason i am attaching a character is so the Vehicle the character is “on” becomes the character’s worldspace, and all vectors become children of that worldspace, making stuff like say localized gravity possible, if you were making a space ship of some kind.
I did some digging and found the part of CharacterMovementComponent that is causing the issue.
void UCharacterMovementComponent::MaybeUpdateBasedMovement(float DeltaSeconds)
{
bDeferUpdateBasedMovement = false;
UPrimitiveComponent* MovementBase = CharacterOwner->GetMovementBase();
if (MovementBaseUtility::UseRelativeLocation(MovementBase))
{
const bool bBaseIsSimulatingPhysics = MovementBase->IsSimulatingPhysics();
// Temporarily disabling deferred tick on skeletal mesh components that sim physics.
// We need to be consistent on when we read the bone locations for those, and while this reads
// the wrong location, the relative changes (which is what we care about) will be accurate.
const bool bAllowDefer = (bBaseIsSimulatingPhysics && !Cast<USkeletalMeshComponent>(MovementBase));
if (!bBaseIsSimulatingPhysics || !bAllowDefer)
{
UpdateBasedMovement(DeltaSeconds);
PreClothComponentTick.SetTickFunctionEnable(false);
}
else
{
// defer movement base update until after physics
bDeferUpdateBasedMovement = true;
PreClothComponentTick.SetTickFunctionEnable(true);
}
}
}
If i could add an exeption in the main if statement it should work just fine and fix the bug.
Is there any known character level flag like bIsAttached or something along those lines?
How do i overrite this function to achieve what is needed?
if (!bBaseIsSimulatingPhysics || !bAllowDefer || !bIsAttached)
{
UpdateBasedMovement(DeltaSeconds);
PreClothComponentTick.SetTickFunctionEnable(false);
}
It would be great if someone could explain what the .h file needs to contain in order to make it work.
void MaybeUpdateBasedMovement(float DeltaSeconds)
{
Super::MaybeUpdateBasedMovement(DeltaSeconds); // Calls the base class
// Add your override logic here
}
good day, sir mr Rama, can i ask you, if you would be so kind to record small video tutorial on how to create custom movement mode. For instance i wanna make custom movement mode for climbing, so my character can walk up down along the wall. I made it with blue prints but i’ve seen also tracing options in the code so i thought that’s gonna be better to sort that from c++… But i don’t really have enough experience to do that myself… Please…