Solved movement and basic replication #1
Binary file not shown.
BIN
Content/Input/Look_IA.uasset
Normal file
BIN
Content/Input/Look_IA.uasset
Normal file
Binary file not shown.
BIN
Content/Input/Move_IA.uasset
Normal file
BIN
Content/Input/Move_IA.uasset
Normal file
Binary file not shown.
Binary file not shown.
@@ -8,6 +8,10 @@ ADDICharacter::ADDICharacter()
|
||||
{
|
||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
||||
CameraComponent->SetupAttachment(GetMesh());
|
||||
CameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f));
|
||||
CameraComponent->bUsePawnControlRotation = true;
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +29,4 @@ void ADDICharacter::Tick(float DeltaTime)
|
||||
|
||||
}
|
||||
|
||||
// Called to bind functionality to input
|
||||
void ADDICharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "DDICharacter.generated.h"
|
||||
|
||||
@@ -23,7 +24,6 @@ public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
// Called to bind functionality to input
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera")
|
||||
UCameraComponent* CameraComponent;
|
||||
};
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
|
||||
|
||||
#include "DDIPlayerController.h"
|
||||
|
||||
#include "DDICharacter.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "Engine/LocalPlayer.h"
|
||||
#include "InputMappingContext.h"
|
||||
#include "GameFramework/Character.h"
|
||||
|
||||
ADDIPlayerController::ADDIPlayerController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ADDIPlayerController::BeginPlay()
|
||||
{
|
||||
@@ -24,7 +28,18 @@ void ADDIPlayerController::BeginPlay()
|
||||
|
||||
void ADDIPlayerController::SetupInputComponent()
|
||||
{
|
||||
// Super::SetupInputComponent();
|
||||
Super::SetupInputComponent();
|
||||
|
||||
if (UEnhancedInputComponent* Subsystem = Cast<UEnhancedInputComponent>(InputComponent))
|
||||
{
|
||||
if (MoveAction) Subsystem->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ADDIPlayerController::Move);
|
||||
if (LookAction) Subsystem->BindAction(LookAction, ETriggerEvent::Triggered, this, &ADDIPlayerController::Look);
|
||||
if (JumpAction)
|
||||
{
|
||||
Subsystem->BindAction(JumpAction, ETriggerEvent::Started, this, &ADDIPlayerController::Jump);
|
||||
Subsystem->BindAction(JumpAction, ETriggerEvent::Completed, this, &ADDIPlayerController::JumpEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ADDIPlayerController::OnPossess(APawn* InPawn)
|
||||
@@ -32,9 +47,54 @@ void ADDIPlayerController::OnPossess(APawn* InPawn)
|
||||
Super::OnPossess(InPawn);
|
||||
|
||||
// is this a shooter character?
|
||||
if (ADDICharacter* DDICharacter = Cast<ADDICharacter>(InPawn))
|
||||
// if (ADDICharacter* DDICharacter = Cast<ADDICharacter>(InPawn))
|
||||
// {
|
||||
// // add the player tag
|
||||
// DDICharacter->Tags.Add(PlayerPawnTag);
|
||||
// }
|
||||
}
|
||||
|
||||
void ADDIPlayerController::Move(const FInputActionValue& Value)
|
||||
{
|
||||
// add the player tag
|
||||
DDICharacter->Tags.Add(PlayerPawnTag);
|
||||
const FVector2D MovementVector = Value.Get<FVector2D>();
|
||||
|
||||
if (APawn* ControlledPawn = GetPawn())
|
||||
{
|
||||
FRotator CameraRotation = GetControlRotation();
|
||||
FRotator YawRotation(0.f, CameraRotation.Yaw, 0.f);
|
||||
|
||||
FVector ForwardDiection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
||||
FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
||||
|
||||
ControlledPawn->AddMovementInput(ForwardDiection, MovementVector.Y);
|
||||
ControlledPawn->AddMovementInput(RightDirection,MovementVector.X);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ADDIPlayerController::Look(const FInputActionValue& Value)
|
||||
{
|
||||
const FVector2D LookAxisVector = Value.Get<FVector2D>();
|
||||
|
||||
if (APawn* ControlledPawn = GetPawn())
|
||||
{
|
||||
AddYawInput(LookAxisVector.X);
|
||||
AddPitchInput(LookAxisVector.Y);
|
||||
}
|
||||
}
|
||||
|
||||
void ADDIPlayerController::Jump(const FInputActionValue& Value)
|
||||
{
|
||||
if (ACharacter* character = GetCharacter())
|
||||
{
|
||||
character->Jump();
|
||||
}
|
||||
}
|
||||
|
||||
void ADDIPlayerController::JumpEnd(const FInputActionValue& Value)
|
||||
{
|
||||
if (ACharacter* character = GetCharacter())
|
||||
{
|
||||
character->StopJumping();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "DDIPlayerController.generated.h"
|
||||
|
||||
@@ -21,9 +23,15 @@ private:
|
||||
|
||||
protected:
|
||||
/*Properties*/
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooter", meta = (AllowPrivateAccess = "true"))
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "INPUT", meta = (AllowPrivateAccess = "true"))
|
||||
TArray<class UInputMappingContext*> MappingContexts;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "INPUT", meta = (AllowPrivateAccess = "true"))
|
||||
UInputAction* JumpAction;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "INPUT", meta = (AllowPrivateAccess = "true"))
|
||||
UInputAction* MoveAction;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "INPUT", meta = (AllowPrivateAccess = "true"))
|
||||
UInputAction* LookAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Shooter")
|
||||
FName PlayerPawnTag = FName("Player");
|
||||
@@ -49,9 +57,14 @@ protected:
|
||||
virtual void SetupInputComponent() override;
|
||||
virtual void BeginPlay() override;
|
||||
virtual void OnPossess(APawn *InPawn) override;
|
||||
void Move(const FInputActionValue& Value);
|
||||
void Look(const FInputActionValue& Value);
|
||||
void Jump(const FInputActionValue& Value);
|
||||
void JumpEnd(const FInputActionValue& Value);
|
||||
|
||||
public:
|
||||
/*Properties*/
|
||||
|
||||
/*Functions*/
|
||||
ADDIPlayerController();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user