-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCharacterPhysicsHandler.cpp
61 lines (46 loc) · 1.31 KB
/
CharacterPhysicsHandler.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
// Fill out your copyright notice in the Description page of Project Settings.
#include "CharacterPhysicsHandler.h"
// Sets default values for this component's properties
UCharacterPhysicsHandler::UCharacterPhysicsHandler()
{
// 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 UCharacterPhysicsHandler::BeginPlay()
{
Super::BeginPlay();
// ...
MyOwner = GetOwner();
}
// Called every frame
void UCharacterPhysicsHandler::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
if(NoOfForceApplied)
{
ApplyForce(DeltaTime);
}
}
void UCharacterPhysicsHandler::AddForce(FVector ForceDir, float ForceMag)
{
Force += ForceDir * ForceMag;
NoOfForceApplied++;
}
void UCharacterPhysicsHandler::ApplyForce(float DeltaTime)
{
if (MyOwner != nullptr)
{
FVector pos = MyOwner->GetActorLocation();
pos += Force * DeltaTime;
MyOwner->SetActorLocation(pos);
}
}
void UCharacterPhysicsHandler::RemoveForce(FVector ForceDir, float ForceMag)
{
Force -= ForceDir * ForceMag;
NoOfForceApplied--;
}