Hello, I’m trying to create different shapes using ProceduralMeshComponent to detect AoE effects in my game. So far I’m able to create all the meshes In the expected shapes that I need, but when dealling with the generation of the collisions for a specific type of areas, such an arch, the generated collisions are not generated following the geometry of the arch itself in the inner side.
Below is just a quick example of how I’m generating a specific section of the mesh and the configuration that I’m using in the constructor.
AAreaEffectShape::AAreaEffectShape()
{
RootComponent = CreateDefaultSubobject<USceneComponent>("Default Root");
ProceduralMeshComponent = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("Mesh"));
ProceduralMeshComponent->SetupAttachment(RootComponent);
ProceduralMeshComponent->SetGenerateOverlapEvents(true);
ProceduralMeshComponent->CanCharacterStepUpOn = ECB_No;
ProceduralMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
ProceduralMeshComponent->SetCollisionResponseToAllChannels(ECR_Overlap);
ProceduralMeshComponent->ClearAllMeshSections();
ProceduralMeshComponent->bUseComplexAsSimpleCollision = false;
}
void AEffectAreaCircle::CreateSection(int SectionIndex)
{
int p2 = 0;
int p3 = 0;
int p0 = Vertices.Add(FVector(Position.X + FMath::Cos(DegreesToRadians(AreaAngle * 0 / NumSteps)) * OuterRadius, Position.Y + FMath::Sin(DegreesToRadians(AreaAngle * 0 / NumSteps)) * OuterRadius, 0.0f));
OuterBottomVertices.Add(p0);
int p1 = Vertices.Add(FVector(Position.X + FMath::Cos(DegreesToRadians(AreaAngle * 0 / NumSteps)) * OuterRadius, Position.Y + FMath::Sin(DegreesToRadians(AreaAngle * 0 / NumSteps)) * OuterRadius, 100.f));
OuterUpperVertices.Add(p1);
for(int i = 1; i < NumSteps; i++)
{
float Angle = DegreesToRadians(AreaAngle * i / NumSteps);
p2 = Vertices.Add(FVector(Position.X + FMath::Cos(Angle) * OuterRadius, Position.Y + FMath::Sin(Angle) * OuterRadius, 0.0f));
p3 = Vertices.Add(FVector(Position.X + FMath::Cos(Angle) * OuterRadius, Position.Y + FMath::Sin(Angle) * OuterRadius, 100.0f));
OuterBottomVertices.Add(p2);
OuterUpperVertices.Add(p3);
CreateTrianglesFromQuad(p0,p1,p2,p3);
p0 = p2;
p1 = p3;
}
UKismetProceduralMeshLibrary::CalculateTangentsForMesh(Vertices, Triangles, UVs, Normals, Tangents);
ProceduralMeshComponent->CreateMeshSection_LinearColor(SectionIndex, Vertices, Triangles, Normals, UVs, VertexColors, Tangents, true);
ProceduralMeshComponent->AddCollisionConvexMesh({Vertices});
}
void AAreaEffectShape::CreateTrianglesFromQuad(int p0, int p1, int p2, int p3)
{
Triangles.Add(p0);
Triangles.Add(p1);
Triangles.Add(p2);
Triangles.Add(p1);
Triangles.Add(p3);
Triangles.Add(p2);
}
After executing the code I’m getting the following result:
My question is the following:
How can I generate the collision area following the arch instead having the inner part going from one side to the opposite one directly?
I’t could be that I’m missing some basic knowledge regarding how collisions are built, I will appreciate any advice related to this topic. It could something related with normals, like the need to generate the mesh double sided as well?