Hey everyone,
So I am working on a melee attack with a sword, which will eventually be able to do things like, chop off zombie limbs or stop a animation if it hits a dense wall or chop through it if it is thin enough, etc… stuff like that, what I have to do first is detect when an object is hitting it, which I am trying to do right now:
This is the code for picking up the item and adding the collision code and later removing the item and collision code:
void APlayerCharacter::Use(AUsableItem* curItem, FName Socket){
curItem->getItemMesh()->SetSimulatePhysics(false);
curItem->SetActorEnableCollision(true);
curItem->getItemMesh()->AttachTo(GetMesh(), Socket, EAttachLocation::SnapToTarget, true);
TScriptDelegate<FWeakObjectPtr> BeginDelegate;
TScriptDelegate<FWeakObjectPtr> EndDelegate;
BeginDelegate.BindUFunction(this, FName("OnWeaponOverlapBegin"));
EndDelegate.BindUFunction(this, FName("OnWeaponOverlapEnd"));
curItem->OnActorBeginOverlap.Add(BeginDelegate);
curItem->OnActorEndOverlap.Add(EndDelegate);
}
void APlayerCharacter::OnWeaponOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool fromSweep, const FHitResult& result){
GEngine->AddOnScreenDebugMessage(1, 1, FColor(1, 1, 1, 100), TEXT("HIT"));
}
void APlayerCharacter::OnWeaponOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex){
GEngine->AddOnScreenDebugMessage(1, 1, FColor(1, 1, 1, 100), TEXT("NoHit"));
}
void APlayerCharacter::RemoveItem(AUsableItem* curItem, FName Socket){
curItem->DetachRootComponentFromParent();
curItem->getItemMesh()->SetSimulatePhysics(true);
curItem->SetActorEnableCollision(true);
//curItem->getItemMesh()->SetCollisionProfileName(TEXT("BlockAll"));
curItem->ApplyWorldOffset((FirstPersonCamera->GetComponentRotation().Vector() * 200), false);
curItem->OnActorBeginOverlap.RemoveAll(Cast<UObject>(curItem));
curItem->OnActorEndOverlap.RemoveAll(Cast<UObject>(curItem));
}
curItem is the melee Weapon, and it should be obvious that I am adding a delegate to when the actor begins/ends overlapping. The Item does work with physics, such as moving boxes around etc… Also I have set up the UFUNCTION() tag in the header with OnWeaponOverlapBegin/End. I cannot seem to figure out what the problem is, but no matter what, I dont see “Hit” being shown on the screen…
Thanks