// Sets default values AMotherActor::AMotherActor() { // 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; UBoxComponent* Box = CreateDefaultSubobject<UBoxComponent>(TEXT("RootComponent")); RootComponent = Box; Box->InitBoxExtent(FVector(20.0f, 20.0f, 20.0f)); UBoxComponent* Box1 = CreateDefaultSubobject<UBoxComponent>(TEXT("Box")); Box1->InitBoxExtent(FVector(60.0f, 60.0f, 60.0f)); Box1->RelativeLocation = FVector(100.0f, 0.0f, 0.0f); USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere")); SphereComponent->InitSphereRadius(60.0f); SphereComponent->RelativeLocation = FVector(100.0f, 0.0f, 0.0f); UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation")); static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere")); if (SphereVisualAsset.Succeeded()) { SphereVisual->SetStaticMesh(SphereVisualAsset.Object); SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -100.0f)); SphereVisual->SetWorldScale3D(FVector(0.8f)); } Box1->AttachTo(RootComponent); SphereVisual->AttachTo(RootComponent); SphereComponent->AttachTo(RootComponent); UChildActorComponent * ChildActor = CreateDefaultSubobject<UChildActorComponent>(TEXT("InventoryCamera")); ChildActor->SetChildActorClass(AOrbitalActor::StaticClass()); ChildActor->CreateChildActor(); FVector position = GetActorLocation(); ChildActor->SetRelativeTransform(FTransform(position)); }
// Called every frame void AHunterProjectile::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); if (GetAttachParentActor()) { return; } FVector deltaMove = DeltaTime * m_velocity; FVector newLocation = GetActorLocation() + deltaMove; SetActorLocation(newLocation, false); AActor *hitActor = FindHitActor(); if (hitActor) { ABasicAIAgent *hitAgent = Cast<ABasicAIAgent>(hitActor); bool doAttach = false; UBoxComponent *attachBox = nullptr; if (hitAgent && hitAgent->m_teamID == TEAM_CALVES) { attachBox = hitAgent->GetSpearBox(); hitAgent->ModifyHealth(-m_projectileDamage); doAttach = true; } else if (ATP_TopDownCharacter *playerChar = Cast<ATP_TopDownCharacter>(hitActor)) { attachBox = playerChar->GetSpearBox(); playerChar->SpearHit(); doAttach = true; } if (attachBox) { FVector boxExtents = attachBox->GetScaledBoxExtent(); FVector boxOrigin = attachBox->GetComponentLocation(); FBox box(boxOrigin - boxExtents, boxOrigin + boxExtents); FVector attachPos = FMath::RandPointInBox(box); SetActorLocation(attachPos); } if (doAttach) { // Destroy(); SetLifeSpan(20.0f); GetRootComponent()->AttachTo(hitActor->GetRootComponent(), NAME_None, EAttachLocation::KeepWorldPosition); OnProjectileHit(); } } }
AMeasurementGate::AMeasurementGate(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass<UBoxComponent>(TEXT("CollisionComp"))) { UBoxComponent* BoxCollisionComponent = CastChecked<UBoxComponent>(GetCollisionComponent()); BoxCollisionComponent->ShapeColor = TriggerBaseColor; BoxCollisionComponent->InitBoxExtent(FVector(40.0f, 40.0f, 40.0f)); static FName CollisionProfileName(TEXT("Trigger")); BoxCollisionComponent->SetCollisionProfileName(CollisionProfileName); if (GetSpriteComponent()) { GetSpriteComponent()->AttachParent = BoxCollisionComponent; } OnActorBeginOverlap.AddDynamic(this, &AMeasurementGate::OnBeginOverlap); }
void AMeasurementGate::EditorApplyScale(const FVector& DeltaScale, const FVector* PivotLocation, bool bAltDown, bool bShiftDown, bool bCtrlDown) { const FVector ModifiedScale = DeltaScale * (AActor::bUsePercentageBasedScaling ? 500.0f : 5.0f); UBoxComponent * BoxComponent = Cast<UBoxComponent>(GetRootComponent()); if (bCtrlDown) { // CTRL+Scaling modifies trigger collision height. This is for convenience, so that height // can be changed without having to use the non-uniform scaling widget (which is // inaccessable with spacebar widget cycling). FVector Extent = BoxComponent->GetUnscaledBoxExtent() + FVector(0, 0, ModifiedScale.X); Extent.Z = FMath::Max(0.0f, Extent.Z); BoxComponent->SetBoxExtent(Extent); } else { FVector Extent = BoxComponent->GetUnscaledBoxExtent() + FVector(ModifiedScale.X, ModifiedScale.Y, ModifiedScale.Z); Extent.X = FMath::Max(0.0f, Extent.X); Extent.Y = FMath::Max(0.0f, Extent.Y); Extent.Z = FMath::Max(0.0f, Extent.Z); BoxComponent->SetBoxExtent(Extent); } }