언리얼 튜토리얼(05) 캐릭터 점프 구현
함수 추가
FPSCharacter.h
// 키를 누르면 점프 플래그를 설정합니다.
UFUNCTION()
void StartJump();
// 키를 떼면 점프 플래그를 지웁니다.
UFUNCTION()
void StopJump();
FPSCharacter.cpp
void AFPSCharacter::StartJump()
{
bPressedJump = true;
}
void AFPSCharacter::StopJump()
{
bPressedJump = false;
}
SetupPlayerInputComponent()에 추가 ↓
// "action" 바인딩을 구성합니다.
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump)
예제 코드
FPSCharacter.h
#pragma once
#include "GameFramework/Character.h"
#include "FPSCharacter.generated.h"
UCLASS()
class FPSPROJECT_API AFPSCharacter : public ACharacter
{
GENERATED_BODY()
public:
// 이 캐릭터 프로퍼티에 대한 기본값을 설정합니다.
AFPSCharacter();
protected:
// 게임 시작 또는 스폰시 호출됩니다.
virtual void BeginPlay() override;
public:
// 매 프레임 호출됩니다.
virtual void Tick( float DeltaSeconds ) override;
// 함수성을 입력에 바인딩하기 위해 호출됩니다.
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
// 전후 이동을 처리합니다.
UFUNCTION()
void MoveForward(float Value);
// 좌우 이동을 처리합니다.
UFUNCTION()
void MoveRight(float Value);
// 키를 누르면 점프 플래그를 설정합니다.
UFUNCTION()
void StartJump();
// 키를 누르면 점프 플래그를 지웁니다.
UFUNCTION()
void StopJump();
};
FPSCharacter.cpp
#include "FPSProject.h"
#include "FPSCharacter.h"
// 기본값을 설정합니다.
AFPSCharacter::AFPSCharacter()
{
// 이 캐릭터가 매 프레임 Tick() 을 호출하도록 설정합니다. 필요치 않은 경우 끄면 퍼포먼스가 향상됩니다.
PrimaryActorTick.bCanEverTick = true;
}
// 게임 시작시 또는 스폰시 호출됩니다.
void AFPSCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
// 디버그 메시지를 5 초간 표시합니다. (첫 인수인) -1 "Key" 값은 이 메시지를 업데이트 또는 새로고칠 필요가 없음을 나타냅니다.
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("We are using FPSCharacter."));
}
}
// 매 프레임 호출됩니다.
void AFPSCharacter::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// 입력에 함수성을 바인딩하기 위해 호출됩니다.
void AFPSCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// "movement" 바인딩을 구성합니다.
PlayerInputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
// "look" 바인딩을 구성합니다.
PlayerInputComponent->BindAxis("Turn", this, &AFPSCharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis("LookUp", this, &AFPSCharacter::AddControllerPitchInput);
// "action" 바인딩을 구성합니다.
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump);
}
void AFPSCharacter::MoveForward(float Value)
{
// 어느 쪽이 전방인지 알아내어, 플레이어가 그 방향으로 이동하려 한다고 기록합니다.
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
void AFPSCharacter::MoveRight(float Value)
{
// 어느 쪽이 오른쪽인지 알아내어, 플레이어가 그 방향으로 이동하려 한다고 기록합니다.
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
AddMovementInput(Direction, Value);
}
void AFPSCharacter::OnStartJump()
{
bPressedJump = true;
}
void AFPSCharacter::OnStopJump()
{
bPressedJump = false;
}
원본
// 키를 누르면 점프 플래그를 설정합니다.
UFUNCTION()
void StartJump();
// 키를 떼면 점프 플래그를 지웁니다.
UFUNCTION()
void StopJump();
void AFPSCharacter::StartJump()
{
bPressedJump = true;
}
void AFPSCharacter::StopJump()
{
bPressedJump = false;
}
SetupPlayerInputComponent()에 추가 ↓
// "action" 바인딩을 구성합니다.
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump)
FPSCharacter.h
#pragma once
#include "GameFramework/Character.h"
#include "FPSCharacter.generated.h"
UCLASS()
class FPSPROJECT_API AFPSCharacter : public ACharacter
{
GENERATED_BODY()
public:
// 이 캐릭터 프로퍼티에 대한 기본값을 설정합니다.
AFPSCharacter();
protected:
// 게임 시작 또는 스폰시 호출됩니다.
virtual void BeginPlay() override;
public:
// 매 프레임 호출됩니다.
virtual void Tick( float DeltaSeconds ) override;
// 함수성을 입력에 바인딩하기 위해 호출됩니다.
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
// 전후 이동을 처리합니다.
UFUNCTION()
void MoveForward(float Value);
// 좌우 이동을 처리합니다.
UFUNCTION()
void MoveRight(float Value);
// 키를 누르면 점프 플래그를 설정합니다.
UFUNCTION()
void StartJump();
// 키를 누르면 점프 플래그를 지웁니다.
UFUNCTION()
void StopJump();
};
FPSCharacter.cpp
#include "FPSProject.h"
#include "FPSCharacter.h"
// 기본값을 설정합니다.
AFPSCharacter::AFPSCharacter()
{
// 이 캐릭터가 매 프레임 Tick() 을 호출하도록 설정합니다. 필요치 않은 경우 끄면 퍼포먼스가 향상됩니다.
PrimaryActorTick.bCanEverTick = true;
}
// 게임 시작시 또는 스폰시 호출됩니다.
void AFPSCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
// 디버그 메시지를 5 초간 표시합니다. (첫 인수인) -1 "Key" 값은 이 메시지를 업데이트 또는 새로고칠 필요가 없음을 나타냅니다.
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("We are using FPSCharacter."));
}
}
// 매 프레임 호출됩니다.
void AFPSCharacter::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// 입력에 함수성을 바인딩하기 위해 호출됩니다.
void AFPSCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
// "movement" 바인딩을 구성합니다.
PlayerInputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
// "look" 바인딩을 구성합니다.
PlayerInputComponent->BindAxis("Turn", this, &AFPSCharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis("LookUp", this, &AFPSCharacter::AddControllerPitchInput);
// "action" 바인딩을 구성합니다.
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump);
}
void AFPSCharacter::MoveForward(float Value)
{
// 어느 쪽이 전방인지 알아내어, 플레이어가 그 방향으로 이동하려 한다고 기록합니다.
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
void AFPSCharacter::MoveRight(float Value)
{
// 어느 쪽이 오른쪽인지 알아내어, 플레이어가 그 방향으로 이동하려 한다고 기록합니다.
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
AddMovementInput(Direction, Value);
}
void AFPSCharacter::OnStartJump()
{
bPressedJump = true;
}
void AFPSCharacter::OnStopJump()
{
bPressedJump = false;
}
원본
캐릭터 점프 구현 튜토리얼을 내가 보기 좋게 정리한 것입니다.
처음 이시라면 축 매핑 튜토리얼을 보고 축 매핑이 선행 되어야 합니다
Author And Source
이 문제에 관하여(언리얼 튜토리얼(05) 캐릭터 점프 구현), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@zin3506/언리얼-튜토리얼05-캐릭터-점프-구현저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)