So, I trying make a simple bullet Reflector in code, nothing special.
I use this code
Constractor:
AReflector::AReflector()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("ReflectorCollision"));
BoxComponent->BodyInstance.bUseCCD = true;
RootComponent = BoxComponent;
BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &AReflector::OnComponentBeginOverlap);
BoxComponent->bGenerateOverlapEvents = true;
Arrow = CreateDefaultSubobject<UArrowComponent>(TEXT("ArrowComponent"));
Arrow->SetupAttachment(BoxComponent);
SetActorEnableCollision(true);
}
Function:
void AReflector::OnComponentBeginOverlap(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Yellow, TEXT("Something!"));
AProjectail* TestProj = Cast<AProjectail>(OtherActor);
if (TestProj)
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, TEXT("Some proj!"));
FVector Velocity = TestProj->ProjectileMovement->Velocity;
Velocity *= (-1);
TestProj->ProjectileMovement->Velocity = FRotator(0, (Arrow->GetComponentRotation().Yaw * 2 - Velocity.Rotation().Yaw), 0).Vector()* Velocity.Size();
}
}
And, as you allready guess, It doesn’t working. It does not fire function, not only from class Projectail, but from anything (Characters, simple actors, anything)
So, any ideas why this … thing not working?