Advertisement
Dieton

MyPawn.cpp

Nov 8th, 2023 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | Gaming | 0 0
  1. //=============================== MyPawn.cpp ===============================//
  2.  
  3. // Fill out your copyright notice in the Description page of Project Settings.
  4.  
  5.  
  6. #include "Pawn/MyPawn.h"
  7. #include "Components/CapsuleComponent.h"
  8. #include "Components/SkeletalMeshComponent.h"
  9. #include "Components/InputComponent.h"
  10. #include "EnhancedInputSubsystems.h"
  11. #include "EnhancedInputComponent.h"
  12.  
  13. // Sets default values
  14. AMyPawn::AMyPawn()
  15. {
  16.     // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  17.     PrimaryActorTick.bCanEverTick = true;
  18.  
  19. }
  20.  
  21. // Called when the game starts or when spawned
  22. void AMyPawn::BeginPlay()
  23. {
  24.     Super::BeginPlay();
  25.    
  26. }
  27.  
  28. void ABird::Move(const FInputActionValue& Value)
  29. {
  30.     /*
  31.     const float DirectionValue = Value.Get<float>();
  32.  
  33.     if (Controller && (DirectionValue != 0.f))
  34.     {
  35.         FVector Forward = GetActorForwardVector();
  36.         AddMovementInput(Forward, DirectionValue);
  37.         //UE_LOG(LogTemp, Warning, TEXT("Weapon.cpp: OtherActor Name: %s"), *BoxHit.GetActor()->GetName());
  38.         ///UE_LOG(LogTemp, Warning, TEXT("IA_Move: %s"), *Forward.ToString());
  39.         //UE_LOG(LogTemp, Warning, TEXT("IA_Move: %f"), DirectionValue);
  40.     }
  41.     */
  42.    
  43.     APawn* Pawn = GetPawn<APawn>();
  44.     const AController* Controller = Pawn ? Pawn->GetController() : nullptr;
  45.  
  46.     if (Controller)
  47.     {
  48.         const FVector2D Value = InputActionValue.Get<FVector2D>();
  49.         const FRotator MovementRotation(0.0f, Controller->GetControlRotation().Yaw, 0.0f);
  50.  
  51.         if (Value.X != 0.0f)
  52.         {
  53.             const FVector MovementDirection = MovementRotation.RotateVector(FVector::RightVector);
  54.             Pawn->AddMovementInput(MovementDirection, Value.X);
  55.         }
  56.  
  57.         if (Value.Y != 0.0f)
  58.         {
  59.             const FVector MovementDirection = MovementRotation.RotateVector(FVector::ForwardVector);
  60.             Pawn->AddMovementInput(MovementDirection, Value.Y);
  61.         }
  62.     }
  63. }
  64.  
  65. // Called every frame
  66. void AMyPawn::Tick(float DeltaTime)
  67. {
  68.     Super::Tick(DeltaTime);
  69.  
  70.    
  71.    
  72.  
  73. }
  74.  
  75.  
  76.  
  77. // Called to bind functionality to input
  78. void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
  79. {
  80.     Super::SetupPlayerInputComponent(PlayerInputComponent);
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement