-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMover.cpp
More file actions
61 lines (41 loc) · 1.89 KB
/
Copy pathMover.cpp
File metadata and controls
61 lines (41 loc) · 1.89 KB
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
55
56
57
58
59
60
61
// Fill out your copyright notice in the Description page of Project Settings.
#include "Mover.h"
#include "Math/UnrealMathUtility.h"
// Sets default values for this component's properties
UMover::UMover()
{
// 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;
// ...
}
// Called when the game starts
void UMover::BeginPlay()
{
Super::BeginPlay();
// ...
OriginalLocation = GetOwner()->GetActorLocation();
}
// Called every frame
void UMover::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
AActor* Owner = GetOwner();//making a pointer name owner which have the memory address location of actor using function GetOwner()
//FString Name = (*Owner).GetActorNameOrLabel()
/*FString Name = Owner->GetActorNameOrLabel();;
FVector OwnerLocation = Owner->GetActorLocation();
FString OwnerLocationString = OwnerLocation.ToCompactString();
UE_LOG(LogTemp,Display,TEXT("Mover owner Name value is: %s and location String is: %s"),*Name,*OwnerLocationString);*/
FVector TargetLocation = OriginalLocation ;//setting the final target location of the door
if(ShouldMove){
TargetLocation = OriginalLocation + MoveOffset;//setting the final target location of the door
}
FVector CurrentLocation = GetOwner()->GetActorLocation();
float Speed = MoveOffset.Length() / MoveTime;
FVector NewLocation = FMath::VInterpConstantTo(CurrentLocation, TargetLocation, DeltaTime, Speed);//function use to interpolate vector and other variables
GetOwner()->SetActorLocation(NewLocation);
}
void UMover::SetShouldMove(bool NewShouldMove) {
ShouldMove= NewShouldMove;
}