Sets default values for this character's properties PlayerCharacter.h #include "CoreMinimal.h"Ĭlass CHARACTERMOVEMENT_API APlayerCharacter : public ACharacter PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput) PlayerInputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput) PlayerInputComponent->BindAxis("MoveRight", this, &APlayerCharacter::MoveRight) PlayerInputComponent->BindAxis("MoveForward", this, &APlayerCharacter::MoveForward) Super::SetupPlayerInputComponent(PlayerInputComponent) Void APlayerCharacter::SetupPlayerInputComponent(UInputComponent*) Next, navigate to the APlayerCharacter::SetupPlayerInputComponent method, and implement the following code. Void APlayerCharacter::MoveRight(float AxisValue)Ĭonst FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y) If ((Controller != nullptr) & (AxisValue != 0.0f))Ĭonst FRotator Rotation = Controller->GetControlRotation() Ĭonst FRotator YawRotation(0, Rotation.Yaw, 0) Ĭonst FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X) Void APlayerCharacter::MoveForward(float AxisValue) In your PlayerCharacter.Cpp, implement the following logic for your APlayerCharacter::MoveForward, and APlayerCharacter::MoveRight class methods. In your PlayerCharacter.h, declare the following class methods In the Bindings Category click the + sign next to Axis Mappings to add the following Axis Mappings. Navigate to Edit > Project Settings > Input, then from the Bindings Category click the + sign next to Action Mappings to add the following Action mappings. You will need to set up some custom logic that will move your character when an Input key such as W,A,S, or D is pressed. In the Editor, navigate to your C++ Classes folder, then right click on your PlayerCharacter class and in the C++ Class Actions drop down menu select Create Blueprint class based on PlayerCharacter. GetCharacterMovement()->bIgnoreBaseRotation = true GetCharacterMovement()->bUseControllerDesiredRotation = true GetCharacterMovement()->bOrientRotationToMovement = true Setting class variables of the Character movement component SpringArmComp->bUsePawnControlRotation = true Setting class variables of the spring arm SpringArmComp->SetupAttachment(GetMesh()) ĬameraComp->SetupAttachment(SpringArmComp,USpringArmComponent::SocketName) Attaching your class Components to the default character's Skeletal Mesh Component. Set the location and rotation of the Character Mesh Transform SpringArmComp = CreateDefaultSubobject(TEXT("SpringArmComp")) ĬameraComp = CreateDefaultSubobject(TEXT("CameraComp")) In the APlayerCharactor::APlayerCharacter constructor method declare the following #include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/SpringArmComponent.h" Navigate to the PlayerCharactor.cpp file and add the following class libraries: UPROPERTY(VisibleAnywhere, BlueprintReadWrite)Ĭlass USpringArmComponent* SpringArmComp Spring Arm Component to follow the camera behind the player In the C++ Class Wizard, create a new Character class named PlayerCharacter, then navigate to the PlayerCharacter.h file and declare the following class definitions: Follow the steps below to set up your character. A character is a pawn that comes with a Character Movement Component to provide a locomotion system for humanoid characters to traverse through your world. A Character class is required for your Player to control.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |