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 "Pawns/Bird.h"
- #include "Components/CapsuleComponent.h"
- #include "Components/SkeletalMeshComponent.h"
- #include "Components/InputComponent.h"
- #include "EnhancedInputSubsystems.h"
- #include "EnhancedInputComponent.h"
- // Sets default values
- ABird::ABird()
- {
- // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
- PrimaryActorTick.bCanEverTick = true;
- //Capule Collider Value
- Capsule = CreateDefaultSubobject<UCapsuleComponent>(TEXT("Capsule"));
- Capsule->SetCapsuleHalfHeight(20.f);
- Capsule->SetCapsuleRadius(15.f);
- SetRootComponent(Capsule);
- //RootComponent = Capsule;
- //Skeletal Mesh Value
- BirdMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("BirdMesh"));
- BirdMesh->SetupAttachment(GetRootComponent());//RootComponent, Capsule,
- AutoPossessPlayer = EAutoReceiveInput::Player0;
- }
- // Called when the game starts or when spawned
- void ABird::BeginPlay()
- {
- Super::BeginPlay();
- APlayerController* PlayerController = Cast<APlayerController>(GetController());//Controller
- UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer());
- if (PlayerController)
- {
- if (Subsystem)
- {
- Subsystem->AddMappingContext(BirdMappingContext,0);
- }
- }
- /*
- ///Avg<int32>(1,3);
- int32 AvgInt = Avg<int32>(1, 3);
- UE_LOG(LogTemp, Warning, TEXT("Avg of 1 and 3: %d"), AvgInt);//%d = descret value for integers
- float AvgFloat = Avg<float>(3.45f, 7.86f);
- UE_LOG(LogTemp, Warning, TEXT("Avg of 3.45 and 7.86: %f"), AvgFloat);//%f is for float
- UE_LOG(LogTemp, Warning, TEXT("Begin Play Call!"));
- if (GEngine)
- {
- GEngine->AddOnScreenDebugMessage(1, 60.f, FColor::Green, FString("Item OnScreen Message!"));
- }
- UWorld* World = GetWorld();
- //SetActorLocation(FVector(0.f, 0.f, 50.f));
- //SetActorRotation(FRotator(0.f,45.f,0.f));
- if (World)
- {
- DrawDebugLine(World, Location, Location+Foward * 100.f, FColor::Red,true,-1.f,0,1.f);
- }
- if (World)
- {
- FVector Location = GetActorLocation();
- DrawDebugSphere(World, Location, 25.f, THIRTY, FColor::Red,false, 30.f);
- }
- if (World)
- {
- DrawDebugPoint(World,Location+Forward * 100.f, 15.f, FColor::Red, true);
- }
- FVector Location = GetActorLocation();
- FVector Forward = GetActorForwardVector();
- DRAW_SPHERE(Location);
- DRAW_LINE(Location, Location + Forward * 100.f);
- DRAW_POINT(Location + Forward * 100.f);
- DRAW_VECTOR(Location, Location + Forward * 100.f);
- */
- }
- void ABird::Move(const FInputActionValue& Value)
- {
- const float DirectionValue = Value.Get<float>();
- if (Controller && (DirectionValue != 0.f))
- {
- FVector Forward = GetActorForwardVector();
- AddMovementInput(Forward, DirectionValue);
- UE_LOG(LogTemp, Warning, TEXT("IA_Move: %f"), DirectionValue);
- }
- }
- // Called every frame
- void ABird::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- /*
- DRAW_SPHERE_SingleFrame(GetActorLocation());
- DRAW_VECTOR_SingleFrame(GetActorLocation(), GetActorLocation() + GetActorForwardVector() * 100.f);
- FVector AvgVector = Avg<FVector>(GetActorLocation(), FVector::ZeroVector);
- DRAW_POINT_SingleFrame(AvgVector);
- //FRotator AvgRotator = Avg<FRotator>(GetActorRotation(), FRotator::ZeroRotator);
- //float DeltaZ = Amplitude * FMath::Sin(RuningTime * TimeConstant); // period = 2*pi/k
- //AddActorWorldOffset(FVector(0.f, 0.f, DeltaZ));
- //movemnt rate in unitys of cm/s
- float MovementRate = 50.f;
- float RotationRate = 45.f;
- //MovementRate * DeltatTime (cm/s) * (s/frame) = (cm/frame)
- AddActorWorldOffset(FVector(MovementRate * DeltaTime,0.f,0.f));
- //Rotation
- AddActorWorldRotation(FRotator(0.f, RotationRate * DeltaTime, 0.f));
- UE_LOG(LogTemp, Warning, TEXT("Begin Play Call!: %f"), DeltaTime);
- if (GEngine)
- {
- FString Name = GetName();
- FString Message1 = FString::Printf(TEXT("Item Name: %s"), *Name);
- FString Message2 = FString::Printf(TEXT("DeltaTime: %f"), DeltaTime);
- GEngine->AddOnScreenDebugMessage(1, 60.f, FColor::Green, Message2);
- UE_LOG(LogTemp, Warning, TEXT("Item Name: %s"), *Name);
- }
- */
- }
- // Called to bind functionality to input
- void ABird::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
- {
- Super::SetupPlayerInputComponent(PlayerInputComponent);
- if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent))
- {
- EnhancedInputComponent->BindAction(MoveAction,ETriggerEvent::Triggered,this, &ABird::Move);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement