I possess a pawn like this
if (AController* controller = GetWorld()->GetFirstPlayerController())
{
controller->UnPossess();
// I added this line to ensure that the velocity is zero but it did nothing
mainPlayer->GetCharacterMovement()->Velocity = FVector::ZeroVector;
mainPlayer->GetCharacterMovement()->DisableMovement();
mainPlayer->GetCharacterMovement()->SetComponentTickEnabled(false);
mainPlayer->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform);
mainPlayer->SetActorTransform(newLocation);
controller->Possess(this);
}
I placed a ship on the ground and I tried possess it, everything works fine but the ship starting moving in a straight line forward!!
I checked the velocity of the movement component but IT’S ZERO
When I un-Possess the ship it stops moving
The movement has nothing to do with the water or the water drag
Could it be the camera or the spring arm ??
springArmComponent->SetupAttachment(GetRootComponent());
SpringArmComponent->SetRelativeRotation(FRotator(-45.f, 0.f, 0.f));
SpringArmComponent->TargetArmLength = 400.f;
SpringArmComponent->bEnableCameraLag = true;
SpringArmComponent->CameraLagSpeed = 2.f;
CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName);
I tried to add this too but it did nothing
SpringArmComponent->bInheritPitch = true;
SpringArmComponent->bInheritYaw = true;
SpringArmComponent->bInheritRoll = false;;
Edit
After debugging I found this is cause because of some weird relationship between the Ship’s static mesh, the player pawn and the cameras.
Disabling the pawn from the ship’s static mesh, seems to fix it but ignoring camera does nothing.
I can’t ignore the pawn from the static mesh because the player pawn will walk through the ship if the pawn is ignored
It’s worth to note that the player has camera and the ship has camera too
Any help is appreciated!!