Created
February 10, 2018 10:32
-
-
Save MattiaPezzanoAiv/897d2eee849dc1991dba9b6844e7d68a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "CurveMovement.h" | |
| // Sets default values for this component's properties | |
| UCurveMovement::UCurveMovement() | |
| { | |
| // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features | |
| // off to improve performance if you don't need them. | |
| PrimaryComponentTick.bCanEverTick = true; | |
| ElapsedTime = 0; | |
| // ... | |
| } | |
| // Called when the game starts | |
| void UCurveMovement::BeginPlay() | |
| { | |
| Super::BeginPlay(); | |
| // ... | |
| } | |
| // Called every frame | |
| void UCurveMovement::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) | |
| { | |
| Super::TickComponent(DeltaTime, TickType, ThisTickFunction); | |
| //update time | |
| ElapsedTime += DeltaTime * Velocity; | |
| //check finish curve | |
| float min = 0; | |
| float max = 0; | |
| Curve->GetTimeRange(min,max); | |
| if (LoopCurve) | |
| { | |
| if (ElapsedTime > max) | |
| ElapsedTime = 0; | |
| } | |
| // get float value | |
| const FVector CurveValue = Curve->GetVectorValue(ElapsedTime); | |
| //move actor | |
| GetOwner()->SetActorLocation(CurveValue); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include "CoreMinimal.h" | |
| #include "Components/ActorComponent.h" | |
| #include "Runtime/Engine/Classes/Curves/CurveVector.h" | |
| #include "Runtime/Engine/Classes/GameFramework/Actor.h" | |
| #include "CurveMovement.generated.h" | |
| UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) | |
| class EXERCISE20180208_API UCurveMovement : public UActorComponent | |
| { | |
| GENERATED_BODY() | |
| public: | |
| // Sets default values for this component's properties | |
| UCurveMovement(); | |
| // Called every frame | |
| virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; | |
| UPROPERTY(EditAnywhere) | |
| UCurveVector* Curve; | |
| UPROPERTY(EditAnywhere) | |
| bool LoopCurve; | |
| UPROPERTY(EditAnywhere) | |
| float Velocity = 1; | |
| protected: | |
| // Called when the game starts | |
| virtual void BeginPlay() override; | |
| private: | |
| float ElapsedTime; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment