Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
- #include "FPSTest.h"
- #include "FPSTestProjectile.h"
- #include "GameFramework/ProjectileMovementComponent.h"
- AFPSTestProjectile::AFPSTestProjectile(const FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- //SetActorTickEnabled(true);
- PrimaryActorTick.bCanEverTick = true;
- // 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, &AFPSTestProjectile::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;
- //Particles!
- Particles = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("Particles"));
- Particles->SetRelativeLocation(FVector::ZeroVector);
- Particles->AttachTo(RootComponent);
- static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticlesInAssets(TEXT("ParticleSystem'/Game/FirstPerson/Particles/P_OrbGlowLights2.P_OrbGlowLights2'"));
- Particles->SetTemplate(ParticlesInAssets.Object);
- //Particles->ActivateSystem(true);
- // Die after 3 seconds by default
- //InitialLifeSpan = 3.0f;
- }
- void AFPSTestProjectile::Tick(float Delta)
- {
- Super::Tick(Delta);
- Particles->SetWorldLocationAndRotation(RootComponent->GetComponentLocation(), RootComponent->GetComponentRotation());
- }
- void AFPSTestProjectile::OnHit(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())
- {
- OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());
- //Destroy();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement