Move AActor with Player Attached (Wrong Physics)

Hey guys

I’m trying to make a ball “walk” when the player is above (the player controls it instead of him).

So I have some problems

  • For the player to be above, I need SetMovementMode(EMovementMode::MOVE_None); but I think it’s not the right way.
  • Using AddActorLocalOffset or SetActorLocation is ignoring collision

I try to use AddForce, but again, I don’t think it’s the right way. I’m using c++.

Follow the code below:

Movement

void ATest::MoveOtherObjectForward(float Value, FVector Direction)
{
    FVector MoveDirection = Direction * Value * Speed;
    //FVector MoveDirection = GetActorLocation() + Direction * Value * Speed;
        
    //AddActorLocalOffset(MoveDirection, true);        
    //SetActorLocation(MoveDirection);

    FVector DeltaLocation = GetActorLocation() + Direction * Value * Speed * GetWorld()->GetDeltaSeconds();

    FHitResult HitResult;
    SetActorLocation(DeltaLocation, true, &HitResult);

    if (HitResult.bBlockingHit)
    {
        //GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, TEXT("Test bBlockingHit"));
    }

    if (HitResult.IsValidBlockingHit())
    {
        //GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, TEXT("Test IsValidBlockingHit"));

        FVector Deflection = FVector::VectorPlaneProject(DeltaLocation, HitResult.ImpactNormal) * (1.f - HitResult.Time);
        AddActorLocalOffset(Deflection, true);
    }
}

When Player enter collision area above

void AInteractiveWool::OnBoxComponentBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    AMyCharacter* PlayerCharacter = Cast<AMyCharacter>(OtherActor);

    if (PlayerCharacter) {
        OtherActor->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform);
        CharacterMovementComponent->SetMovementMode(EMovementMode::MOVE_None);
    }
}

Another detail, this ball that I’m trying to move with the player, is inheriting from the AActor