Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sets default values
- AClientPawn::AClientPawn()
- {
- // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
- PrimaryActorTick.bCanEverTick = true;
- mainMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RootComponent"));
- springArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
- camera = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
- RootComponent = mainMesh;
- springArm->SetupAttachment(RootComponent);
- springArm->TargetArmLength = 300.0f;
- springArm->TargetOffset = FVector(0.0f, 0.0f, 50.0f);
- springArm->SocketOffset = FVector(0.0f, 0.0f, 150.0f);
- camera->SetupAttachment(springArm);
- walkSpeed = 100.0f;
- turnSpeed = 45.0f;
- }
- // Called when the game starts or when spawned
- void AClientPawn::BeginPlay()
- {
- Super::BeginPlay();
- }
- // Called every frame
- void AClientPawn::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- CameraMovement(100.0f, 100.0f);
- PlayerMovement();
- }
- void AClientPawn::MoveRightServer_Implementation(float Value)
- {
- moveRight = Value;
- }
- void AClientPawn::MoveForwardServer_Implementation(float Value)
- {
- moveForward = Value;
- }
- void AClientPawn::CameraMovement(float SensitivityX, float SensitivityY)
- {
- // CAMERA MOVEMENT
- FRotator NewRotation = springArm->GetComponentRotation();
- NewRotation.Pitch = FMath::Clamp(NewRotation.Pitch + CameraInput.Y * GetWorld()->GetDeltaSeconds() * SensitivityY, -60.0f, 15.0f);
- NewRotation.Yaw = NewRotation.Yaw + CameraInput.X * GetWorld()->GetDeltaSeconds() * SensitivityX;
- NewRotation.Roll = 0.0f;
- springArm->SetWorldRotation(NewRotation);
- }
- void AClientPawn::PlayerMovement()
- {
- //ClientLocation += moveForward * walkSpeed * GetActorForwardVector() * GetWorld()->GetDeltaSeconds();
- AddActorWorldRotation(FRotator(0.0f, moveRight * turnSpeed * GetWorld()->GetDeltaSeconds(), 0.0f));
- //SetActorLocation(ClientLocation);
- AddMovementInput(GetActorForwardVector(), moveForward);
- }
- void AClientPawn::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
- {
- Super::GetLifetimeReplicatedProps(OutLifetimeProps);
- DOREPLIFETIME(AClientPawn ,moveForward);
- DOREPLIFETIME(AClientPawn, moveRight);
- DOREPLIFETIME(AClientPawn, walkSpeed);
- }
- // Called to bind functionality to input
- void AClientPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
- {
- Super::SetupPlayerInputComponent(PlayerInputComponent);
- PlayerInputComponent->BindAxis(TEXT("MouseX"), this, &AClientPawn::YawCamera);
- PlayerInputComponent->BindAxis(TEXT("MouseY"), this, &AClientPawn::PitchCamera);
- PlayerInputComponent->BindAxis(TEXT("Forward"), this, &AClientPawn::MoveForward);
- PlayerInputComponent->BindAxis(TEXT("Right"), this, &AClientPawn::MoveRight);
- PlayerInputComponent->BindAction(TEXT("Test"), IE_Pressed, this, &AClientPawn::TestInput);
- }
- void AClientPawn::PitchCamera(float Value) {
- CameraInput.Y = Value;
- }
- void AClientPawn::YawCamera(float Value) {
- CameraInput.X = Value;
- }
- void AClientPawn::MoveForward(float Value)
- {
- MoveForwardServer(Value);
- }
- void AClientPawn::MoveRight(float Value)
- {
- MoveRightServer(Value);
- }
- void AClientPawn::TestInput()
- {
- ChangeWalkSpeed();
- }
- void AClientPawn::ChangeWalkSpeed_Implementation()
- {
- walkSpeed = 300.0f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement