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);
|
GadgetManager = Cast<AGadgetManager>(GadgetManagerActor);
|
||||||
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);
|
||||||
GadgetManagerActor->AttachToComponent(GetRootComponent(), AttachmentRules);
|
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
|
//////////////////////////////////////////////////////////////////////////// Input
|
||||||
|
@ -32,6 +32,9 @@ protected:
|
|||||||
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
|
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
|
||||||
FVector EquippedOffset = FVector(0, 0, 0);
|
FVector EquippedOffset = FVector(0, 0, 0);
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, Category = "Gadget")
|
||||||
|
FRotator GadgetRotation = FRotator(0, 0, 0);
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, CAtegory = "Gadget")
|
UPROPERTY(EditDefaultsOnly, CAtegory = "Gadget")
|
||||||
FVector UnequippedOffset = FVector(0, 0, -1000);
|
FVector UnequippedOffset = FVector(0, 0, -1000);
|
||||||
|
|
||||||
@ -74,6 +77,10 @@ public:
|
|||||||
return UnequippedOffset;
|
return UnequippedOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FRotator GetGadgetSpawnRotation()
|
||||||
|
{
|
||||||
|
return GadgetRotation;
|
||||||
|
}
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
AGadgetBase();
|
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"));
|
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);
|
AActor* SpawnedActor = GetWorld()->SpawnActor<AActor>(ReconClass, GetActorLocation(), GetActorRotation(), SpawnParams);
|
||||||
ReconGadget = Cast<AReconGadget>(SpawnedActor);
|
ReconGadget = Cast<AReconGadget>(SpawnedActor);
|
||||||
SpawnedActor->AttachToComponent(PlayersRootComponent, AttachmentRules);
|
SpawnedActor->AttachToComponent(PlayersCameraComponent, AttachmentRules);
|
||||||
SpawnedActor->SetActorRelativeLocation(ReconGadget->GetUnequippedOffset());
|
SpawnedActor->SetActorRelativeLocation(ReconGadget->GetUnequippedOffset());
|
||||||
|
SpawnedActor->SetActorRelativeRotation(ReconGadget->GetGadgetSpawnRotation());
|
||||||
|
|
||||||
SpawnedActor = GetWorld()->SpawnActor<AActor>(CombatClass, GetActorLocation(), GetActorRotation(), SpawnParams);
|
SpawnedActor = GetWorld()->SpawnActor<AActor>(CombatClass, GetActorLocation(), GetActorRotation(), SpawnParams);
|
||||||
CombatGadget = Cast<ACombatGadget>(SpawnedActor);
|
CombatGadget = Cast<ACombatGadget>(SpawnedActor);
|
||||||
SpawnedActor->AttachToComponent(PlayersRootComponent, AttachmentRules);
|
SpawnedActor->AttachToComponent(PlayersCameraComponent, AttachmentRules);
|
||||||
SpawnedActor->SetActorRelativeLocation(CombatGadget->GetUnequippedOffset());
|
SpawnedActor->SetActorRelativeLocation(CombatGadget->GetUnequippedOffset());
|
||||||
|
SpawnedActor->SetActorRelativeRotation(CombatGadget->GetGadgetSpawnRotation());
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ protected:
|
|||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void SpawnGadgets(USceneComponent* PlayersRootComponent);
|
void SpawnGadgets(USceneComponent* PlayersCameraComponent);
|
||||||
|
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
AGadgetManager();
|
AGadgetManager();
|
||||||
|
Loading…
Reference in New Issue
Block a user