Announcement

Collapse
No announcement yet.

Newbie needing help plz and thanks

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Newbie needing help plz and thanks

    Hi, I'm trying to follow along with this tutorial Time stamp in video is 11.00 to 14.00 but finding it slightly hard as i'm new to Unreal 4. I'm trying to follow along but dunno where it has gone wrong, I know he has done it in a previous version from 4.22.3 (currenly using). If someone is willing to spend a little bit of time to help me i would be very greatful.

    Code:
    void AG_nadeProjectile::BeginPlay()
    {
        Super::BeginPlay();
    
        FTimerHandle T_Handle;
        //GetWorld()->GetTimerManager().SetTimer(T_Handle, this, &AG_nadeProjectile::OnDetonate, 5.f, false);
    
    }
    
    void AG_nadeProjectile::OnDetonate()
    {
        UParticleSystemComponent* Explosion = UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ExplosionParticies, GetActorTransform());
        //Explosion->SetRelativeScale3D(FVector(4.f));
        //Explosion
        //UGameplayStatics::PlaySoundAtLocation(GetWorld(), ExplosionSound, GetActorLocation());
        //UGameplayStatics::PlaySoundAtLocation();
    
        TArray<FHitResult> HitActors;
    
        FVector StartTrace = GetActorLocation();
        FVector EndTrace = StartTrace;
        EndTrace.Z += 300.f;
    
        FCollisionShape CollisionShape;
        CollisionShape.ShapeType = ECollisionShape::Sphere;
        CollisionShape.SetSphere(Radius);
    
        if (GetWorld()->SweepMultiByChannel(HitActors, StartTrace, EndTrace, FQuat::FQuat(), ECC_WorldStatic, CollisionShape))
        {
            for (auto Actors = HitActors.CreateIterator(); Actors; Actors++)
            {
                UStaticMeshComponent* SM = Cast<UStaticMeshComponent>((*Actors).Actor->GetRootComponent());
                ADestructibleActor* DA = Cast<ADestructibleActor>((*Actors).GetActor());
    
                if (SM)
                {
    
    
                    SM->ApplyRadialDamage(GetActorLocation(), 140, 10, ERadialImpulseFalloff::RIF_Linear, false);
                }
                else if(DA)
                {
                    DA->GetDestructibleComponent()->ApplyRadialDamage(10.f, Actors->ImpactPoint, 500.f, 3000.f, false);
                }
    
            }
    
    
    
    
        }
    
        Destroy();
    
    }
    Click image for larger version

Name:	Capture.PNG
Views:	72
Size:	147.6 KB
ID:	1680843
    Attached Files

    #2
    Hi,
    The C2027 error is probably that you need to include this in your G_nadeProjectile.cpp file:

    #include "DestructibleComponent.h"

    https://docs.unrealengine.com/en-US/...ent/index.html

    If that are more errors, could you post your .h and .cpp file with #includes?

    Comment


      #3
      ****** Header *****
      Code:
      // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
      
      #pragma once
      #include "Kismet/GameplayStatics.h"
      #include <vector>
      #include "CoreMinimal.h"
      #include "GameFramework/Actor.h"
      #include "Components/PostProcessComponent.h"
      #include "Components/TimelineComponent.h"
      #include "G_nadeProjectile.generated.h"
      
      UCLASS(config=Game)
      class AG_nadeProjectile : public AActor
      {
          GENERATED_BODY()
      
          /** Sphere collision component */
          UPROPERTY(VisibleDefaultsOnly, Category=Projectile)
          class USphereComponent* CollisionComp;
      
          /** Projectile movement component */
          UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = "true"))
          class UProjectileMovementComponent* ProjectileMovement;
      
          UPROPERTY(EditAnywhere, Category = "FX")
          class UParticleSystem* ExplosionParticies;
      
          UPROPERTY(EditAnywhere, Category = "SOUND_FX")
              class USoundCue* ExplosionSound;
          UPROPERTY(EditAnywhere, Category = "Projectile")
              float Radius = 500.f;
      
      public:
          AG_nadeProjectile();
      
          virtual void BeginPlay() override;
      
          UFUNCTION()
          void OnDetonate();
      
          /** called when projectile hits something */
          UFUNCTION()
          void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
      
          /** Returns CollisionComp subobject **/
          FORCEINLINE class USphereComponent* GetCollisionComp() const { return CollisionComp; }
          /** Returns ProjectileMovement subobject **/
          FORCEINLINE class UProjectileMovementComponent* GetProjectileMovement() const { return ProjectileMovement; }
      };
      ****** CPP *******


      Code:
      // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
      
      #include "G_nadeProjectile.h"
      #include "GameFramework/ProjectileMovementComponent.h"
      #include "Components/SphereComponent.h"
      #include "DestructibleActor.h"
      #include "DestructibleComponent.h"
      #include "DrawDebugHelpers.h"
      
      
      
      AG_nadeProjectile::AG_nadeProjectile()
      {
          // Use a sphere as a simple collision representation
          CollisionComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
          CollisionComp->InitSphereRadius(5.0f);
          CollisionComp->BodyInstance.SetCollisionProfileName("Projectile");
          CollisionComp->OnComponentHit.AddDynamic(this, &AG_nadeProjectile::OnHit);        // set up a notification for when this component hits something blocking
      
          // Players can't walk on it
          CollisionComp->SetWalkableSlopeOverride(FWalkableSlopeOverride(WalkableSlope_Unwalkable, 0.f));
          CollisionComp->CanCharacterStepUpOn = ECB_No;
      
          // Set as root component
          RootComponent = CollisionComp;
      
          // Use a ProjectileMovementComponent to govern this projectile's movement
          ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileComp"));
          ProjectileMovement->UpdatedComponent = CollisionComp;
          ProjectileMovement->InitialSpeed = 3000.f;
          ProjectileMovement->MaxSpeed = 3000.f;
          ProjectileMovement->bRotationFollowsVelocity = true;
          ProjectileMovement->bShouldBounce = true;
      
          // Die after 3 seconds by default
          InitialLifeSpan = 3.0f;
      }
      
      void AG_nadeProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
      {
          // Only add impulse and destroy projectile if we hit a physics
          if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && OtherComp->IsSimulatingPhysics())
          {
              OnDetonate();
          }
      }
      
      void AG_nadeProjectile::BeginPlay()
      {
          Super::BeginPlay();
      
          FTimerHandle T_Handle;
          //GetWorld()->GetTimerManager().SetTimer(T_Handle, this, &AG_nadeProjectile::OnDetonate, 5.f, false);
      
      }
      
      void AG_nadeProjectile::OnDetonate()
      {
          UParticleSystemComponent* Explosion = UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ExplosionParticies, GetActorTransform());
          //Explosion->SetRelativeScale3D(FVector(4.f));
          //Explosion
          //UGameplayStatics::PlaySoundAtLocation(GetWorld(), ExplosionSound, GetActorLocation());
          //UGameplayStatics::PlaySoundAtLocation();
      
          TArray<FHitResult> HitActors;
      
          FVector StartTrace = GetActorLocation();
          FVector EndTrace = StartTrace;
          EndTrace.Z += 300.f;
      
          FCollisionShape CollisionShape;
          CollisionShape.ShapeType = ECollisionShape::Sphere;
          CollisionShape.SetSphere(Radius);
      
          if (GetWorld()->SweepMultiByChannel(HitActors, StartTrace, EndTrace, FQuat::FQuat(), ECC_WorldStatic, CollisionShape))
          {
              for (auto Actors = HitActors.CreateIterator(); Actors; Actors++)
              {
                  UStaticMeshComponent* SM = Cast<UStaticMeshComponent>((*Actors).Actor->GetRootComponent());
                  ADestructibleActor* DA = Cast<ADestructibleActor>((*Actors).GetActor());
      
                  if (SM)
                  {
      
      
                      SM->ApplyRadialDamage(GetActorLocation(), 140, 10, ERadialImpulseFalloff::RIF_Linear, false);
                  }
                  else if(DA)
                  {
                      DA->GetDestructibleComponent()->ApplyRadialDamage(10.f, Actors->ImpactPoint, 500.f, 3000.f, false);
                  }
      
              }
      
      
      
      
          }
      
          Destroy();
      
      }

      Comment


        #4
        Fixed it, i was to sleeply last night. You helped plus i was trying to apply a radialdamge to the SM instead of the AddRadialImpulse after that i re-run it and it worked thanks for the help SolidSk

        Comment

        Working...
        X