Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "KiritoCharacter.h"
- #include "GameFramework/SpringArmComponent.h"
- #include "GameFramework/CharacterMovementComponent.h"
- #include "Camera/CameraComponent.h"
- #define def(func) void AKiritoCharacter::func
- //i hate boiler plate code and duplication of code, which is why i made this definition
- // Sets default values
- AKiritoCharacter::AKiritoCharacter()
- {
- SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("spring arm component"));
- CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("camera component"));
- GetMesh()->SetRelativeLocationAndRotation(FVector(.0f, .0f, -90.0f), FQuat(FRotator(.0f, -90.0f, .0f)));
- SpringArmComp->SetupAttachment(GetMesh());
- CameraComp->SetupAttachment(SpringArmComp, USpringArmComponent::SocketName);
- SpringArmComp->bUsePawnControlRotation = true;
- GetCharacterMovement()->bOrientRotationToMovement = GetCharacterMovement()->bUseControllerDesiredRotation = GetCharacterMovement()->bIgnoreBaseRotation = true;
- PrimaryActorTick.bCanEverTick = true;
- }
- // Called when the game starts or when spawned
- def(BeginPlay)()
- {
- Super::BeginPlay();
- }
- // Called every frame
- def(Tick)(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- }
- // Called to bind functionality to input
- def(SetupPlayerInputComponent)(UInputComponent* PlayerInputComponent)
- {
- Super::SetupPlayerInputComponent(PlayerInputComponent);
- PlayerInputComponent->BindAxis("MoveForward", this, &AKiritoCharacter::MoveForward);
- PlayerInputComponent->BindAxis("MoveRight", this, &AKiritoCharacter::MoveRight);
- PlayerInputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
- PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
- PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
- PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
- PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, &AKiritoCharacter::BeginCrouch);
- PlayerInputComponent->BindAction("Crouch", IE_Released, this, &AKiritoCharacter::EndCrouch);
- PlayerInputComponent->BindAction("Sprint", IE_Pressed, this, &AKiritoCharacter::BeginSprint);
- PlayerInputComponent->BindAction("Sprint", IE_Released, this, &AKiritoCharacter::EndSprint);
- }
- def(MoveForward)(float axisValue) {
- if (axisValue != .0f) {
- const FRotator YawRotation(.0, Controller->GetControlRotation().Yaw, .0);
- AddMovementInput(FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X), axisValue);
- }
- }
- def(MoveRight)(float axisValue) {
- if (axisValue != .0f) {
- const FRotator YawRotation(.0, Controller->GetControlRotation().Yaw, .0);
- AddMovementInput(FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y), axisValue);
- }
- }
- def(BeginSprint)() {
- GetCharacterMovement()->MaxWalkSpeed = 1000.0f;
- }
- def(EndSprint)() {
- GetCharacterMovement()->MaxWalkSpeed = 600.0f;
- }
- def(BeginCrouch)() {
- Crouch();
- }
- def(EndCrouch)() {
- UnCrouch();
- }
- // Fill out your copyright notice in the Description page of Project Settings.
- #pragma once
- #include "CoreMinimal.h"
- #include "GameFramework/Character.h"
- #include "UsefulDefs.h"
- #include "KiritoCharacter.generated.h"
- UCLASS()
- class IHATEUNREALENGINE_API AKiritoCharacter : public ACharacter
- {
- GENERATED_BODY()
- public:
- // Sets default values for this character's properties
- AKiritoCharacter();
- protected:
- UPROP_VA_BRW
- class USpringArmComponent* SpringArmComp;
- UPROP_VA_BRW
- class UCameraComponent* CameraComp;
- void BeginSprint();
- void EndSprint();
- void BeginCrouch();
- void EndCrouch();
- void MoveForward(float InputAxis);
- void MoveRight(float InputAxis);
- virtual void BeginPlay() override;
- public:
- // Called every frame
- virtual void Tick(float DeltaTime) override;
- // Called to bind functionality to input
- virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement