rotating sub static mesh does not respect collision detection
I have a UE4 c++ application that rotates static meshes that are attached to other static meshes. Here there is a center sphere with three legs, cylinders, each with an attached subleg, cylinder. If I rotate the subleg, the collision detection with the floor works correctly, but if I rotate the main leg, the subleg passes through the floor, the collision detection is not working. I have researched online, but none of the solutions have worked. The code is below.
change:
#define USE_CYL1 false - the sub leg rotates, works correctly
#define USE_CYL1 true - the main leg rotates, does not work correctly, no collision detection
thank you
(Test2Pawn.cpp)
#include "Test2Pawn.h"
#define USE_CYL1 false
float cummTime = 0.0f;
float DeltaDir = +10.0f;
float MinRotation = USE_CYL1 ? 90.0f : 30.0f;
float MaxRotation = USE_CYL1 ? 120.0f : 60.0f;
float CylRotation = USE_CYL1 ? MaxRotation : MaxRotation;
UStaticMeshComponent* Cyl11;
UStaticMeshComponent* Cyl12;
UStaticMeshComponent* Cyl21;
UStaticMeshComponent* Cyl22;
UStaticMeshComponent* Cyl31;
UStaticMeshComponent* Cyl32;
ATest2Pawn::ATest2Pawn()
{
PrimaryActorTick.bCanEverTick = true;
cummTime = 0.0f;
((USphereComponent*)RootComponent)->SetSphereRadius(50.0f, true);
const float Scale = GetCollisionComponent()->GetUnscaledSphereRadius() / 160.f;
GetMeshComponent()->SetRelativeScale3D(FVector(Scale));
static ConstructorHelpers::FObjectFinder<UStaticMesh> MeshAsset(*FString("/Game/StarterContent/Shapes/Shape_Cylinder.Shape_Cylinder"));
Cyl11 = CreateDefaultSubobject<UStaticMeshComponent>(FName("Cyl11"));
Cyl11->SetStaticMesh(MeshAsset.Object);
Cyl11->SetupAttachment(RootComponent);
Cyl11->SetRelativeRotation(FRotator(90.0f, 0.0f, 0.0f));
Cyl11->SetWorldScale3D(FVector(1, 1, 4));
Cyl12 = CreateDefaultSubobject<UStaticMeshComponent>(FName("Cyl12"));
Cyl12->SetStaticMesh(MeshAsset.Object);
Cyl12->SetupAttachment(Cyl11);
Cyl12->SetRelativeLocation(FVector(0.0f, 0.0f, 100.0f));
Cyl12->SetRelativeRotation(FRotator(60.0f, 0.0f, 0.0f));
Cyl21 = CreateDefaultSubobject<UStaticMeshComponent>(FName("Cyl21"));
Cyl21->SetStaticMesh(MeshAsset.Object);
Cyl21->SetupAttachment(RootComponent);
Cyl21->SetRelativeRotation(FRotator(90.0f, 0.0f, 120.0f));
Cyl21->SetWorldScale3D(FVector(1, 1, 4));
Cyl22 = CreateDefaultSubobject<UStaticMeshComponent>(FName("Cyl22"));
Cyl22->SetStaticMesh(MeshAsset.Object);
Cyl22->SetupAttachment(Cyl21);
Cyl22->SetRelativeLocation(FVector(0.0f, 0.0f, 100.0f));
Cyl22->SetRelativeRotation(FRotator(60.0f, 0.0f, 0.0f));
Cyl31 = CreateDefaultSubobject<UStaticMeshComponent>(FName("Cyl31"));
Cyl31->SetStaticMesh(MeshAsset.Object);
Cyl31->SetupAttachment(RootComponent);
Cyl31->SetRelativeRotation(FRotator(90.0f, 0.0f, 240.0f));
Cyl31->SetWorldScale3D(FVector(1, 1, 4));
Cyl32 = CreateDefaultSubobject<UStaticMeshComponent>(FName("Cyl32"));
Cyl32->SetStaticMesh(MeshAsset.Object);
Cyl32->SetupAttachment(Cyl31);
Cyl32->SetRelativeLocation(FVector(0.0f, 0.0f, 100.0f));
Cyl32->SetRelativeRotation(FRotator(60.0f, 0.0f, 0.0f));
}
void ATest2Pawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
cummTime += DeltaTime;
if (cummTime < 2)
{
return;
}
if (USE_CYL1)
{
Cyl11->SetRelativeRotation(FRotator(CylRotation, 0.0f, 0.0f));
}
else
{
Cyl12->SetRelativeRotation(FRotator(CylRotation, 0.0f, 0.0f));
}
if (CylRotation <= MinRotation) { DeltaDir = +10.0f; }
if (CylRotation >= MaxRotation) { DeltaDir = -10.0f; }
CylRotation += DeltaDir * DeltaTime;
}
(Test2ProjectGameModeBase.cpp)
#include “Test2ProjectGameModeBase.h”
ATest2ProjectGameModeBase::ATest2ProjectGameModeBase()
{
UE_LOG(LogTemp, Log, TEXT("Start version 8"));
}
void ATest2ProjectGameModeBase::BeginPlay()
{
Super::BeginPlay();
ATest2Pawn* test2Pawn1 = GetWorld()->SpawnActor<ATest2Pawn>(ATest2Pawn::StaticClass(), FVector(0, 0, 400), FRotator(0, 0, 0), FActorSpawnParameters());
USphereComponent* test2Pawn1Collision = test2Pawn1->GetCollisionComponent();
test2Pawn1Collision->SetSimulatePhysics(true);
test2Pawn1Collision->SetEnableGravity(true);
}