Advertisement
orfeasel

Floating Actor source file

Jan 17th, 2016
13,553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. // Sets default values
  2. AFloatingActor::AFloatingActor()
  3. {
  4.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  5.     PrimaryActorTick.bCanEverTick = true;
  6.  
  7.     //Initializing the static mesh of the actor
  8.     StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
  9. }
  10.  
  11. // Called when the game starts or when spawned
  12. void AFloatingActor::BeginPlay()
  13. {
  14.     Super::BeginPlay();
  15.  
  16.     //Checking if the curvefloat that was entered in the blueprint was valid
  17.     if (CurveFloat)
  18.     {
  19.         /*The ProgressFunction contains the signature of the function that is
  20.         going to execute every time we tick our timeline.
  21.         Think of the progressfunction as a delegate!*/
  22.         FOnTimelineFloat ProgressFunction;
  23.  
  24.         /*In order to bind the function our ufunction we need to create a FName which contains
  25.         the name of the function we want to call every time the timeline advances.
  26.         Binding the HandleProgress function to the ProgressFunction...*/
  27.         ProgressFunction.BindUFunction(this, FName("HandleProgress"));
  28.  
  29.         //Setting up the loop status and the function that is going to fire when the timeline ticks
  30.         MyTimeline.AddInterpFloat(CurveFloat, ProgressFunction);
  31.         MyTimeline.SetLooping(true);
  32.  
  33.         /*Initializing our home and target location in order to make the actor float between them.
  34.         As you can see the two locations have the same X and Y but their Z value is different.*/
  35.         ActorInitialLocation = TargetLocation = GetActorLocation();
  36.         TargetLocation.Z += MaxBounceHeight;
  37.  
  38.         //Starting the timeline...
  39.         MyTimeline.PlayFromStart();
  40.     }
  41. }
  42.  
  43. // Called every frame
  44. void AFloatingActor::Tick( float DeltaTime )
  45. {
  46.     Super::Tick( DeltaTime );
  47.  
  48.     //Advancing the timeline in every tick
  49.     MyTimeline.TickTimeline(DeltaTime);
  50. }
  51.  
  52. void AFloatingActor::HandleProgress(float Value)
  53. {
  54.     //Setting up the new location of our actor
  55.     FVector NewLocation = FMath::Lerp(ActorInitialLocation, TargetLocation, Value);
  56.     SetActorLocation(NewLocation);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement