Hi,
Been trying for a good hour or so to get my overlap detection to work between a wall and a capsule component.
Heres the relevant code:
void AFirstPersonCharacter::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult){
if (OtherActor) {
UE_LOG(LogTemp, Warning, TEXT("youve done it, the overlap works now??"))
if (OtherActor->ActorHasTag(TEXT("RunWall")) && (GetCharacterMovement()->IsFalling() == true)) {
JumpCount = 0;
FVector ForwardVectorCam = Cam->GetForwardVector();
OnWall = true;
while ((SpaceHeld == true) && (OnWall == true)) {
GetCharacterMovement()->GravityScale = 0;
GetCharacterMovement()->SetPlaneConstraintNormal(FVector(0.f, 0.f, 1.f));
Player->AddForce(ForwardVectorCam * MomentumMultiplier());
}
}
}
}
void AFirstPersonCharacter::BeginPlay()
{
Super::BeginPlay();
Player->OnComponentBeginOverlap.AddDynamic(this, &AFirstPersonCharacter::OnOverlapBegin);
Player->OnComponentEndOverlap.AddDynamic(this, &AFirstPersonCharacter::OnOverlapEnd); //initially these were in the tick function but I read somewhere that they had to be in the beginplay function.
}
void AFirstPersonCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
float SpaceHeldTime = GetWorld()->GetFirstPlayerController()->GetInputKeyTimeDown("SpaceBar");
if (SpaceHeldTime > 0.f) {
SpaceHeld = true;
}
void AFirstPersonCharacter::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) {
OnWall = false;
GetCharacterMovement()->SetPlaneConstraintNormal(FVector(0.f, 0.f, 0.f));
GetCharacterMovement()->GravityScale = 1.0f;
}
.h
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void OnOverlapEnd(UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
The problem is there are no error messages, just no working solution currently. I previously had issues with the AddDynamic part of the OnComponentBeginOverlap part but that was fixed with updating some of the arguments. The walls have their generate overlap events ticked, as does the player.
The logger I placed in the overlap begin function should run as soon as I touch the wall, so it’s definitely not a problem with the rest of the code (not yet anyway!), rather a problem with the detection itself.
Any ideas would be very welcome, thanks.