119 lines
3.2 KiB
C++
119 lines
3.2 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Components/ActorComponent.h"
|
|
#include "MarbleMovementComponent.generated.h"
|
|
|
|
class USphereComponent;
|
|
|
|
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
|
class BIGMARBLEWORLD_API UMarbleMovementComponent : public UActorComponent
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
// Sets default values for this component's properties
|
|
UMarbleMovementComponent();
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Marble|Movement")
|
|
void SetMoveDirection(FVector WorldDirection);
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Marble|Movement")
|
|
void BeginJump();
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Marble|Jump")
|
|
void EndJump();
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Marble|State")
|
|
bool IsGrounded() const;
|
|
|
|
// Called when the game starts
|
|
virtual void BeginPlay() override;
|
|
|
|
// Called every frame
|
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
|
|
FActorComponentTickFunction* ThisTickFunction) override;
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "Marble|Network")
|
|
bool IsLocallyControlling() const;
|
|
|
|
protected:
|
|
|
|
UFUNCTION(Server, Unreliable)
|
|
void ServerSetMoveDirection(FVector WorldDirection);
|
|
|
|
UFUNCTION(Server, Unreliable)
|
|
void ServerSyncTransform(
|
|
FVector_NetQuantize100 Location,
|
|
FRotator Rotation,
|
|
FVector_NetQuantize100 LinearVel,
|
|
FVector_NetQuantize100 AngularVel
|
|
);
|
|
|
|
UFUNCTION(NetMulticast, Unreliable)
|
|
void MulticastSyncTransform(
|
|
FVector_NetQuantize100 Location,
|
|
FRotator Rotation,
|
|
FVector_NetQuantize100 LinearVel,
|
|
FVector_NetQuantize100 AngularVel
|
|
);
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Movement")
|
|
float RollForce = 1200.0f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Movement")
|
|
float MaxAngularSpeed = 8.0f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Movement")
|
|
float MoveForce = 400.0f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Movement")
|
|
float MaxLinearSpeed = 1200.0f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Movement")
|
|
float AerialControlFactor = 0.3f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Jump")
|
|
float JumpInitialImpulse = 350.0f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Jump")
|
|
float JumpHoldForce = 1800.0f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Jump")
|
|
float MaxJumpHoldDuration = 0.3f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Jump")
|
|
float GroundCheckDistance = 5.0f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Network")
|
|
float SyncSendRate = 20.0f;
|
|
|
|
UPROPERTY(EditAnywhere, Category = "Marble|Network")
|
|
float ProxyCorrectionSpeed = 10.0f;
|
|
|
|
private:
|
|
|
|
UPROPERTY(Transient)
|
|
TObjectPtr<USphereComponent> PhysicsSphere; // Resolved from owner
|
|
|
|
UPROPERTY(BlueprintReadOnly, Category = "Marble|Movement", meta = (AllowPrivateAccess = "true"))
|
|
FVector CachedMoveDirection = FVector::ZeroVector;
|
|
|
|
float SyncTimer = 0.0f;
|
|
|
|
bool bIsJumping = false;
|
|
float JumpHoldElapsed = 0.0f;
|
|
|
|
FVector_NetQuantize100 ProxyTargetLocation;
|
|
FRotator ProxyTargetRotation = FRotator::ZeroRotator;
|
|
FVector_NetQuantize100 ProxyTargetLinearVel;
|
|
FVector_NetQuantize100 ProxyTargetAngularVel;
|
|
bool bHasProxyTarget = false;
|
|
|
|
void TickControlling(float DeltaTime);
|
|
void TickProxy(float DeltaTime);
|
|
|
|
};
|