Hello there,
I’m having a small problem when opening a door.
I can rotate my door (open it) but it looks like some collision is not updated. Also, I can go through the Static Mesh, when it’s open.
Below there is a small video showing what’s happening.
Here’s the code:
Constructor:
Scene = CreateDefaultSubobject<USceneComponent>( TEXT("Scene"));
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
SetRootComponent(Scene);
StaticMesh->AttachToComponent(Scene, FAttachmentTransformRules::KeepRelativeTransform);
StaticMesh->SetMobility(EComponentMobility::Movable);
StaticMesh->SetCollisionObjectType(ECollisionChannel::ECC_WorldDynamic);
StaticMesh->CanCharacterStepUpOn = ECanBeCharacterBase::ECB_No;
StaticMesh->SetCanEverAffectNavigation(true);
Code that opens/closes the door:
float LocalRotation = 0.f;
if (WasUsed)
{
//StaticMesh->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
LocalRotation = -90;
UE_LOG(LogTemp, Warning, TEXT("Opened"))
}
else {
//StaticMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
LocalRotation = 90;
UE_LOG(LogTemp , Warning, TEXT("Closed"))
}
FRotator Rotator = StaticMesh->GetComponentRotation();
FRotator NewRotator = FRotator(Rotator.Roll, Rotator.Yaw + LocalRotation, Rotator.Pitch);
StaticMesh->SetWorldRotation(NewRotator);