I tried creating an in-house Mantle System, but I’m having an issue with Line Trace For Objects in cpp.
I made sure that:
Trace Channel (FloorTrace) in Colision Preset has Collision Response set to Block.
Each prop in the map as the same Collision Preset.
But still shows that there’s no hit at all.
// Called when the game starts
void UCndPlayerMoveComponent::BeginPlay()
{
Super::BeginPlay();
// Get Component Owner
PlayerCharacter = Cast<ACharacter>(GetOwner());
WDS_CollisionShape = FCollisionShape::MakeSphere(20.0f);
FCollisionQueryParams LV_CollisionQuery;
LV_CollisionQuery.AddIgnoredActor(PlayerCharacter);
WDS_CollisionQueryParams = LV_CollisionQuery;
FCollisionObjectQueryParams LV_CollisionObjectQuery;
LV_CollisionObjectQuery.AddObjectTypesToQuery(EMS_TraceChannel);
WDS_CollisionObjectQueryParams = LV_CollisionObjectQuery;
FHitResult LV_HitResult;
WDS_HitResult = LV_HitResult;
}
void UCndPlayerMoveComponent::BP_Func_Move_CheckObstacle_Faced()
{
float LV_Player_RayCastHeight_Start = 5.0f; // Adjust the Height of Starting Position of Line Trace
float LV_Player_RayCastHeight_End = 75.0f; // Adjust the Height of End Position of Line Trace
float LV_Player_RayCastPos_Start = 50.0f; // Adjust the Forward Distance of Starting Position of Line Trace
float LV_Player_RayCastDistance = 300.0f; // Adjust the Line Trace Distance
FVector LV_PlayerLoc = PlayerCharacter->GetActorLocation();
FVector LV_PlayerForwardVector = PlayerCharacter->GetActorForwardVector();
FVector LV_PlayerLoc_ForwardVector =
PlayerCharacter->GetActorForwardVector() * LV_Player_RayCastDistance;
FVector LV_Wall_Face_Start = LV_PlayerLoc + LV_PlayerForwardVector * LV_Player_RayCastPos_Start + FVector(0, 0, LV_Player_RayCastHeight_Start);
FVector LV_Wall_Face_End = LV_Wall_Face_Start + LV_PlayerLoc_ForwardVector + FVector(0, 0, LV_Player_RayCastHeight_End);
FHitResult LV_HitResult;
WDS_HitResult = LV_HitResult;
// Perform the Line Trace - Detect Faced Obstacle
bool bHitWall_Face = GetWorld()->LineTraceSingleByObjectType(
WDS_HitResult,
LV_Wall_Face_Start, LV_Wall_Face_End,
WDS_CollisionObjectQueryParams, WDS_CollisionQueryParams // Refer to "WDS - Ray Cast Collision Queries" in "Begin Play"
);
// - DEBUG AREA: Start
if (EMS_DEBUG_Enabled)
{
FString DEBUG_HitWallFace = bHitWall_Face ? TEXT("True") : TEXT("False");
GEngine->AddOnScreenDebugMessage(-1, 0.f, FColor::White, FString::Printf(TEXT("EMS - Wall: %s"), *DEBUG_HitWallFace));
if (bHitWall_Face)
{
GEngine->AddOnScreenDebugMessage(
-1,
0.f, // Message Duration
FColor::Green, // Debug Message Color
TEXT("EMS Mantle: Wall Detected!")
);
// Draw the debug line
DrawDebugLine(
GetWorld(),
LV_Wall_Face_Start,
LV_Wall_Face_End,
FColor::Green, // Color of the line
false, // Persistent (will stay in the world)
1.0f, // Lifetime of the line
0, // Depth priority
2.0f // Line thickness
);
}
}
// - DEBUG AREA: End
if (bHitWall_Face) // Raycast Hit? = True
{
WDS_Wall_Loc = WDS_HitResult.Location;
WDS_Wall_Normal = WDS_HitResult.Normal;
// Get WDS_Wall_Normal > Make Rot from X > Get Forward Vector
WDS_Wall_ForwardVector = FRotationMatrix::MakeFromX(WDS_Wall_Normal).GetUnitAxis(EAxis::X);
BP_Func_Move_CheckObstacle_Height();
}
else
{
if (EMS_DEBUG_Enabled)
{
GEngine->AddOnScreenDebugMessage(
-1,
0.f, // Message Duration
FColor::Red, // Debug Message Color
TEXT("EMS Mantle: No wall detected.")
);
// Draw the debug line
DrawDebugLine(
GetWorld(),
LV_Wall_Face_Start,
LV_Wall_Face_End,
FColor::Red, // Color of the line
false, // Persistent (will stay in the world)
1.0f, // Lifetime of the line
0, // Depth priority
2.0f // Line thickness
);
}
}
}
WARNING! Solely Liking ( ) post without providing help will result in my action of removing this post.