Switched Gadget Attachment Point to Players Camera
This commit is contained in:
parent
9c2a1abeab
commit
5e36b9e25e
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
@ -54,7 +54,13 @@ void AEndlessVendettaCharacter::BeginPlay()
|
||||
GadgetManager = Cast<AGadgetManager>(GadgetManagerActor);
|
||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||
GadgetManagerActor->AttachToComponent(GetRootComponent(), AttachmentRules);
|
||||
GadgetManager->SpawnGadgets(GetRootComponent());
|
||||
for (UActorComponent* PlayersCamera : GetComponentsByTag(UCameraComponent::StaticClass(), FName("PlayersCamera")))
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("An actor component with PlayersCamera tag has been found"));
|
||||
GadgetManager->SpawnGadgets(Cast<USceneComponent>(PlayersCamera));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////// Input
|
||||
|
@ -32,6 +32,9 @@ protected:
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
|
||||
FVector EquippedOffset = FVector(0, 0, 0);
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
|
||||
FRotator GadgetRotation = FRotator(0, 0, 0);
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, CAtegory = "Gadget")
|
||||
FVector UnequippedOffset = FVector(0, 0, -1000);
|
||||
|
||||
@ -73,7 +76,11 @@ public:
|
||||
{
|
||||
return UnequippedOffset;
|
||||
}
|
||||
|
||||
|
||||
FRotator GetGadgetSpawnRotation()
|
||||
{
|
||||
return GadgetRotation;
|
||||
}
|
||||
// Sets default values for this actor's properties
|
||||
AGadgetBase();
|
||||
|
||||
|
@ -25,7 +25,7 @@ void AGadgetManager::Tick(float DeltaTime)
|
||||
|
||||
}
|
||||
|
||||
void AGadgetManager::SpawnGadgets(USceneComponent* PlayersRootComponent)
|
||||
void AGadgetManager::SpawnGadgets(USceneComponent* PlayersCameraComponent)
|
||||
{
|
||||
if (!IsValid(ReconClass) || !IsValid(CombatClass)) UE_LOG(LogTemp, Fatal, TEXT("Recon or Combat class hasn't been set"));
|
||||
|
||||
@ -35,11 +35,13 @@ void AGadgetManager::SpawnGadgets(USceneComponent* PlayersRootComponent)
|
||||
|
||||
AActor* SpawnedActor = GetWorld()->SpawnActor<AActor>(ReconClass, GetActorLocation(), GetActorRotation(), SpawnParams);
|
||||
ReconGadget = Cast<AReconGadget>(SpawnedActor);
|
||||
SpawnedActor->AttachToComponent(PlayersRootComponent, AttachmentRules);
|
||||
SpawnedActor->AttachToComponent(PlayersCameraComponent, AttachmentRules);
|
||||
SpawnedActor->SetActorRelativeLocation(ReconGadget->GetUnequippedOffset());
|
||||
SpawnedActor->SetActorRelativeRotation(ReconGadget->GetGadgetSpawnRotation());
|
||||
|
||||
SpawnedActor = GetWorld()->SpawnActor<AActor>(CombatClass, GetActorLocation(), GetActorRotation(), SpawnParams);
|
||||
CombatGadget = Cast<ACombatGadget>(SpawnedActor);
|
||||
SpawnedActor->AttachToComponent(PlayersRootComponent, AttachmentRules);
|
||||
SpawnedActor->AttachToComponent(PlayersCameraComponent, AttachmentRules);
|
||||
SpawnedActor->SetActorRelativeLocation(CombatGadget->GetUnequippedOffset());
|
||||
SpawnedActor->SetActorRelativeRotation(CombatGadget->GetGadgetSpawnRotation());
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
void SpawnGadgets(USceneComponent* PlayersRootComponent);
|
||||
void SpawnGadgets(USceneComponent* PlayersCameraComponent);
|
||||
|
||||
// Sets default values for this actor's properties
|
||||
AGadgetManager();
|
||||
|
Loading…
Reference in New Issue
Block a user