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.
|
// 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;
|
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
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "Camera/CameraComponent.h"
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "DDICharacter.generated.h"
|
#include "DDICharacter.generated.h"
|
||||||
|
|
||||||
@@ -23,7 +24,6 @@ public:
|
|||||||
// Called every frame
|
// Called every frame
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
// Called to bind functionality to input
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera")
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
UCameraComponent* CameraComponent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "DDIPlayerController.h"
|
#include "DDIPlayerController.h"
|
||||||
|
#include "EnhancedInputComponent.h"
|
||||||
#include "DDICharacter.h"
|
|
||||||
#include "EnhancedInputSubsystems.h"
|
#include "EnhancedInputSubsystems.h"
|
||||||
#include "Engine/LocalPlayer.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "InputMappingContext.h"
|
|
||||||
|
ADDIPlayerController::ADDIPlayerController()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ADDIPlayerController::BeginPlay()
|
void ADDIPlayerController::BeginPlay()
|
||||||
{
|
{
|
||||||
@@ -24,7 +28,18 @@ void ADDIPlayerController::BeginPlay()
|
|||||||
|
|
||||||
void ADDIPlayerController::SetupInputComponent()
|
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)
|
void ADDIPlayerController::OnPossess(APawn* InPawn)
|
||||||
@@ -32,9 +47,54 @@ void ADDIPlayerController::OnPossess(APawn* InPawn)
|
|||||||
Super::OnPossess(InPawn);
|
Super::OnPossess(InPawn);
|
||||||
|
|
||||||
// is this a shooter character?
|
// 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)
|
||||||
|
{
|
||||||
|
const FVector2D MovementVector = Value.Get<FVector2D>();
|
||||||
|
|
||||||
|
if (APawn* ControlledPawn = GetPawn())
|
||||||
{
|
{
|
||||||
// add the player tag
|
FRotator CameraRotation = GetControlRotation();
|
||||||
DDICharacter->Tags.Add(PlayerPawnTag);
|
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
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "EnhancedInputComponent.h"
|
||||||
|
#include "EnhancedInputSubsystems.h"
|
||||||
#include "GameFramework/PlayerController.h"
|
#include "GameFramework/PlayerController.h"
|
||||||
#include "DDIPlayerController.generated.h"
|
#include "DDIPlayerController.generated.h"
|
||||||
|
|
||||||
@@ -21,9 +23,15 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*Properties*/
|
/*Properties*/
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Shooter", meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "INPUT", meta = (AllowPrivateAccess = "true"))
|
||||||
TArray<class UInputMappingContext*> MappingContexts;
|
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")
|
UPROPERTY(EditAnywhere, Category="Shooter")
|
||||||
FName PlayerPawnTag = FName("Player");
|
FName PlayerPawnTag = FName("Player");
|
||||||
@@ -49,9 +57,14 @@ protected:
|
|||||||
virtual void SetupInputComponent() override;
|
virtual void SetupInputComponent() override;
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
virtual void OnPossess(APawn *InPawn) 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:
|
public:
|
||||||
/*Properties*/
|
/*Properties*/
|
||||||
|
|
||||||
/*Functions*/
|
/*Functions*/
|
||||||
|
ADDIPlayerController();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user