Hi. I’m trying to make seamless portals. The teleport to the target portal seems okay but when it collides on teleported it sends the character further from the intended location
here is the video: Video
When the character collides with the frame it was sent to a different location.
Here is my code for the actor teleportation
void UPortalComponent::TeleportActor(AActor* ActorTeleport)
{
if (ActorTeleport == nullptr || PortalActor == nullptr)
return;
if (TeleportPortal == nullptr)
TeleportPortal = GetPortalComponentFromActor(PortalActor);
const FVector NewPosition = URowelMathLibrary::ConvertLocationToOtherActorSpace(ActorTeleport->GetActorLocation(),this, TeleportPortal);
const FVector NewVelocity = CalculateVelocityOnTeleport(ActorTeleport);
FHitResult *HitLocation = nullptr;
ActorTeleport->SetActorEnableCollision(false);
ActorTeleport->SetActorLocation(NewPosition, false, HitLocation, ETeleportType::ResetPhysics);
ACharacter* Character = Cast<ACharacter>(ActorTeleport);
if (Character != nullptr)
{
const FRotator NewRotation = URowelMathLibrary::ConvertRotationToOtherActorSpace(Character->GetControlRotation(), this, TeleportPortal);
Character->GetController()->SetControlRotation(NewRotation);
Character->GetCharacterMovement()->Velocity = NewVelocity;
}
else
{
const FRotator NewRotation = URowelMathLibrary::ConvertRotationToOtherActorSpace(ActorTeleport->GetActorRotation(), this, TeleportPortal);
ActorTeleport->SetActorRotation(NewRotation, ETeleportType::ResetPhysics);
ActorTeleport->GetRootComponent()->ComponentVelocity = NewVelocity;
}
ActorTeleport->SetActorEnableCollision(true);
}
I’m not sure how to approach this problem. Should I do a Capsule trace before teleporting the character/Actor and move it a little bit based on the impact normal of the trace? or is there a way when the capsule collided with something it just snaps back to the nearest position of the collision?