Hello everyone.
I’m trying to make a turn based game on a 3D hexagonal tile based environment. The level data (2D array) will be received from server and then the tiles are spawned using spawn actor function. (server yet to be implemented).
I’m using “Maximo Animation Pack” and spawned one character using BlueprintImplementableEvent and enabled simulate physics on capsule collider component.
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "SpawnCharacterbyType"), Category = "CharaterSpawning")
APawn* SpawnCharacterByType(FName pCharacterType, FVector pPosition);
and using this function to spawn the character as APawn* and enabling the capsule collider’s simulate physics.
character = SpawnCharacterByType(FName("Mixamo_Adam"),FVector(410.0f, 0.0f, 350.0f));
TArray<UCapsuleComponent*> characterComponents;
if (character != NULL) {
character->GetComponents<UCapsuleComponent>(characterComponents);
}
else {
UE_LOG(LogTemp, Log, TEXT("character is null"));
return;
}
UCapsuleComponent* characterCapsuleComponent = characterComponents[0];
characterCapsuleComponent->SetSimulatePhysics(true);
I googled alot on how to move character and there are many solutions and I tried everything. Character moves but its not doing walk animating. It is behaving like a static mesh just sliding like its position being updated in Tick.
Here are list of things i tried:
Method 1:
Implemented AddActorLocalOffset function in blueprint as BlueprintImplementableEvent and called it inside Tick().
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "MoveCharacter"), Category = "Move")
bool MoveCharacter( APawn* pCharacter, FVector pDirection, float pValue, bool pIsForce );
Blueprint implementation of this function:
When I run this, character just slide for sometime and falls down. Worst part is character keeps sliding but when he is about to fall he does walk animation. He does animation only when he is falling. I uploaded the video please look at the video.
[Youtube video of character sliding and animating while falling][4]
Method 2:
Everything is same as method 1 expect that this time I used AddMomentInput in MoveCharacter function in blueprint.
I read that for AddMomentInput to work the character needs to be possessed by a controller. So I did this after spawning the character.
AController* controller = GetWorld()->GetFirstPlayerController();
controller->Possess(character);
But this time, character is not moving at all.
Method 3:
I thought of using the AI navigation system. So I created a NavMeshBoundsVolume and made it very large so that is encompass all the level. In character blueprint I made the AI Controller Class as “AIController”.
I tried moving character using C++ and also blueprints both are not working.
In C++, I creates a function called SimpleMoveToLocation in NavigationSystem.
void ALevelCreator::SetNewMoveDestination(const FVector pDestination) {
UE_LOG(LogTemp, Log, TEXT("character setting nav points"));
UNavigationSystem* NavSys = UNavigationSystem::GetCurrent(GetWorld());
if (NavSys == NULL) {
UE_LOG(LogTemp, Log, TEXT("NavSys is NULL"));
return;
}
NavSys->SimpleMoveToLocation(character->GetController(), FVector(800.0f, 0.0f, 300.0f));
}
In OutputLog this is what that came.
LogTemp: character setting nav points
LogNavigation:Warning: UNavigationSystem::SimpleMoveToActor called for NavSys:None Controller:None controlling Pawn:NULL (if any of these is None then there’s your problem)
Even in this method, character is not moving at all. Of course with so many values as null its expected that character wont be moving.
These are the three methods I tired. I’m very new to unreal engine and i’m trying to learn the engine. I hope i explained my problem and everything I tried clearly so that you have all info before replying me. Please direct me in direction.
Thanks in advance.