/
OpenableObject.cpp
76 lines (63 loc) · 2.03 KB
/
OpenableObject.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Fill out your copyright notice in the Description page of Project Settings.
#include "Survival.h"
#include "OpenableObject.h"
AOpenableObject::AOpenableObject()
{
PrimaryActorTick.bCanEverTick = true;
InteractableObjectStaticMesh->SetSimulatePhysics(false);
_canBePutToInventory = false;
_key = 0;
_locked = false;
_animate = false;
_openSpeed = 200.0f;
}
void AOpenableObject::BeginPlay()
{
Super::BeginPlay();
initialRotationYaw = InteractableObjectStaticMesh->GetComponentRotation().Yaw;
}
void AOpenableObject::SetIsInteracted(bool _isInteracted)
{
Super::SetIsInteracted(_isInteracted);
_animate = true;
_openClose = !_openClose;
}
void AOpenableObject::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (_animate)
{
float openCloseSpeed;
float objectRotationZ = InteractableObjectStaticMesh->GetComponentRotation().Yaw;
if (_openDirection)
{
openCloseSpeed = _openSpeed * DeltaTime * (_openClose == true ? 1 : -1);
InteractableObjectStaticMesh->SetRelativeRotation(FRotator(0.f, objectRotationZ + openCloseSpeed, 0.f));
if (objectRotationZ < initialRotationYaw)
{
InteractableObjectStaticMesh->SetRelativeRotation(FRotator(0.f, initialRotationYaw, 0.f));
_animate = false;
}
else if (objectRotationZ > initialRotationYaw + 80.f)
{
InteractableObjectStaticMesh->SetRelativeRotation(FRotator(0.f, initialRotationYaw + 80.f, 0.f));
_animate = false;
}
}
else
{
openCloseSpeed = _openSpeed * DeltaTime * (_openClose == true ? -1 : 1);
InteractableObjectStaticMesh->SetRelativeRotation(FRotator(0.f, objectRotationZ + openCloseSpeed, 0.f));
if (objectRotationZ > initialRotationYaw)
{
InteractableObjectStaticMesh->SetRelativeRotation(FRotator(0.f, initialRotationYaw, 0.f));
_animate = false;
}
else if (objectRotationZ < initialRotationYaw - 80.f)
{
InteractableObjectStaticMesh->SetRelativeRotation(FRotator(0.f, initialRotationYaw - 80.f, 0.f));
_animate = false;
}
}
}
}