File size: 1,383 Bytes
8d44bc8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | // Copyright Epic Games, Inc. All Rights Reserved.
#include "SideScrollingNPC.h"
#include "Engine/World.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "TimerManager.h"
ASideScrollingNPC::ASideScrollingNPC()
{
PrimaryActorTick.bCanEverTick = true;
GetCharacterMovement()->MaxWalkSpeed = 150.0f;
}
void ASideScrollingNPC::EndPlay(EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
// clear the deactivation timer
GetWorld()->GetTimerManager().ClearTimer(DeactivationTimer);
}
void ASideScrollingNPC::Interaction(AActor* Interactor)
{
// ignore if this NPC has already been deactivated
if (bDeactivated)
{
return;
}
// reset the deactivation flag
bDeactivated = true;
// stop character movement immediately
GetCharacterMovement()->StopMovementImmediately();
// launch the NPC away from the interactor
FVector LaunchVector = Interactor->GetActorForwardVector() * LaunchImpulse;
LaunchVector.Y = 0.0f;
LaunchVector.Z = LaunchVerticalImpulse;
LaunchCharacter(LaunchVector, true, true);
// set up a timer to schedule reactivation
GetWorld()->GetTimerManager().SetTimer(DeactivationTimer, this, &ASideScrollingNPC::ResetDeactivation, DeactivationTime, false);
}
void ASideScrollingNPC::ResetDeactivation()
{
// reset the deactivation flag
bDeactivated = false;
}
|