-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncPhysics.h
42 lines (30 loc) · 1.44 KB
/
SyncPhysics.h
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
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Net/UnrealNetwork.h"
#include "SyncPhysics.generated.h"
UCLASS(ClassGroup = (Physics), meta = (BlueprintSpawnableComponent))
class YOUR_PROJECT_API USyncPhysics : public UActorComponent
{
GENERATED_BODY()
public:
USyncPhysics();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Physics Replication")
bool bEnablePhysicsReplication;
protected:
virtual void BeginPlay() override;
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Replication", Replicated)
FVector LastPosition;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Replication", Replicated)
FVector LastVelocity;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Replication", Replicated)
FRotator LastRotation;
void ReplicatePhysics();
void ApplyPhysicsState(const FVector& NewPosition, const FVector& NewVelocity, const FRotator& NewRotation);
UFUNCTION(Server, Reliable, WithValidation)
void Server_SyncPhysicsState(const FVector& NewPosition, const FVector& NewVelocity, const FRotator& NewRotation);
private:
UPrimitiveComponent* RootComp;
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
};