Advertisement
Guest User

Untitled

a guest
Jun 8th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
  2.  
  3. #include "FPSTest.h"
  4. #include "FPSTestProjectile.h"
  5. #include "GameFramework/ProjectileMovementComponent.h"
  6.  
  7. AFPSTestProjectile::AFPSTestProjectile(const FObjectInitializer& ObjectInitializer)
  8.     : Super(ObjectInitializer)
  9. {
  10.     //SetActorTickEnabled(true);
  11.     PrimaryActorTick.bCanEverTick = true;
  12.     // Use a sphere as a simple collision representation
  13.     CollisionComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
  14.     CollisionComp->InitSphereRadius(5.0f);
  15.     CollisionComp->BodyInstance.SetCollisionProfileName("Projectile");
  16.     CollisionComp->OnComponentHit.AddDynamic(this, &AFPSTestProjectile::OnHit);     // set up a notification for when this component hits something blocking
  17.  
  18.     // Players can't walk on it
  19.     CollisionComp->SetWalkableSlopeOverride(FWalkableSlopeOverride(WalkableSlope_Unwalkable, 0.f));
  20.     CollisionComp->CanCharacterStepUpOn = ECB_No;
  21.  
  22.     // Set as root component
  23.     RootComponent = CollisionComp;
  24.  
  25.     // Use a ProjectileMovementComponent to govern this projectile's movement
  26.     ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileComp"));
  27.     ProjectileMovement->UpdatedComponent = CollisionComp;
  28.     ProjectileMovement->InitialSpeed = 3000.f;
  29.     ProjectileMovement->MaxSpeed = 3000.f;
  30.     ProjectileMovement->bRotationFollowsVelocity = true;
  31.     ProjectileMovement->bShouldBounce = true;
  32.  
  33.     //Particles!
  34.     Particles = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("Particles"));
  35.     Particles->SetRelativeLocation(FVector::ZeroVector);
  36.     Particles->AttachTo(RootComponent);
  37.    
  38.  
  39.     static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticlesInAssets(TEXT("ParticleSystem'/Game/FirstPerson/Particles/P_OrbGlowLights2.P_OrbGlowLights2'"));
  40.  
  41.     Particles->SetTemplate(ParticlesInAssets.Object);
  42.    
  43.     //Particles->ActivateSystem(true);
  44.  
  45.     // Die after 3 seconds by default
  46.     //InitialLifeSpan = 3.0f;
  47. }
  48.  
  49. void AFPSTestProjectile::Tick(float Delta)
  50. {
  51.     Super::Tick(Delta);
  52.     Particles->SetWorldLocationAndRotation(RootComponent->GetComponentLocation(), RootComponent->GetComponentRotation());
  53. }
  54.  
  55. void AFPSTestProjectile::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
  56. {
  57.     // Only add impulse and destroy projectile if we hit a physics
  58.     if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && OtherComp->IsSimulatingPhysics())
  59.     {
  60.         OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());
  61.  
  62.         //Destroy();
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement