diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini index 29bf928..c44327e 100755 --- a/Config/DefaultInput.ini +++ b/Config/DefaultInput.ini @@ -101,6 +101,10 @@ DoubleClickTime=0.200000 +AxisMappings=(AxisName="MoveRight",Scale=-1.000000,Key=A) +AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=Gamepad_LeftY) +AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=Gamepad_LeftX) ++AxisMappings=(AxisName="YawXUpdate",Scale=1.000000,Key=Gamepad_RightX) ++AxisMappings=(AxisName="YawXUpdate",Scale=1.000000,Key=MouseX) ++AxisMappings=(AxisName="YawYUpdate",Scale=-1.000000,Key=Gamepad_RightY) ++AxisMappings=(AxisName="YawYUpdate",Scale=-1.000000,Key=MouseY) DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks -ConsoleKeys=Tilde +ConsoleKeys=Tilde diff --git a/Content/GameModeBase_BP.uasset b/Content/GameModeBase_BP.uasset index f5d85d2..ca30461 100755 Binary files a/Content/GameModeBase_BP.uasset and b/Content/GameModeBase_BP.uasset differ diff --git a/Content/TestMap.umap b/Content/TestMap.umap index 65883e0..4cc2ab4 100755 Binary files a/Content/TestMap.umap and b/Content/TestMap.umap differ diff --git a/Content/TestMap_BuiltData.uasset b/Content/TestMap_BuiltData.uasset index 51dfcd2..359a46f 100755 Binary files a/Content/TestMap_BuiltData.uasset and b/Content/TestMap_BuiltData.uasset differ diff --git a/Source/PresidentsBrigade/BasePawn.cpp b/Source/PresidentsBrigade/BasePawn.cpp index 1660885..032b0ea 100755 --- a/Source/PresidentsBrigade/BasePawn.cpp +++ b/Source/PresidentsBrigade/BasePawn.cpp @@ -96,28 +96,39 @@ void ABasePawn::Tick(float DeltaTime) void ABasePawn::handle_move_forward(float axis) { - FRotator rotation = Controller->GetControlRotation(); - FRotator yaw(0.0f, rotation.Yaw, 0.0f); - - FVector forward = FRotationMatrix(yaw).GetUnitAxis(EAxis::X); - AddMovementInput(forward, axis); + if (axis != 0) + { + FVector forward = FRotationMatrix(FRotator()).GetUnitAxis(EAxis::X); + AddMovementInput(forward, axis); + } } void ABasePawn::handle_move_right(float axis) { - FRotator rotation = Controller->GetControlRotation(); - FRotator yaw(0.0f, rotation.Yaw, 0.0f); + if (axis != 0) + { + FVector right = FRotationMatrix(FRotator()).GetUnitAxis(EAxis::Y); + AddMovementInput(right, axis); + } +} - FVector right = FRotationMatrix(yaw).GetUnitAxis(EAxis::Y); - AddMovementInput(right, axis); +void ABasePawn::update_yaw_x(float x_component) +{ + yaw.x_component = x_component; +} + +void ABasePawn::update_yaw_y(float y_component) +{ + yaw.y_component = y_component; } void ABasePawn::shoot() { FVector player_location = player_mesh->GetComponentLocation(); - FRotator rotation = Controller->GetControlRotation(); - FRotator yaw(0.0f, rotation.Yaw, 0.0f); - FVector forward = FRotationMatrix(yaw).GetUnitAxis(EAxis::X) * 100; + const float y = yaw.calculate_yaw(); + LogInfo(FString::Printf(TEXT("Raw yaw: %f"), y)); + const FRotator rotator(0, y, 0); + FVector forward = FRotationMatrix(rotator).GetUnitAxis(EAxis::X) * 100; FVector spawn_location = player_location + forward; FActorSpawnParameters spawnParameters; @@ -127,7 +138,7 @@ void ABasePawn::shoot() AActor* bullet = GetWorld()->SpawnActor( bullet_actor_class, spawn_location, - FRotator(0,0,0), + rotator, spawnParameters ); } diff --git a/Source/PresidentsBrigade/BasePawn.h b/Source/PresidentsBrigade/BasePawn.h index b2fb8dd..7656888 100755 --- a/Source/PresidentsBrigade/BasePawn.h +++ b/Source/PresidentsBrigade/BasePawn.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "GameFramework/Pawn.h" #include "Components/BoxComponent.h" +#include "Kismet/KismetMathLibrary.h" #include "BasePawn.generated.h" class UFloatingPawnMovement; @@ -24,9 +25,28 @@ public: virtual void Tick(float DeltaTime) override; virtual void handle_move_right(float axis); virtual void handle_move_forward(float axis); + virtual void update_yaw_x(float x_component); + virtual void update_yaw_y(float y_component); virtual void shoot(); virtual void handle_death(); protected: + struct Yaw + { + float x_component; + float y_component; + + float calculate_yaw() + { + if (x_component < 0) + { + const float deg = UKismetMathLibrary::DegAtan2(-1 * x_component, y_component); + return 360 - deg; + } + + return UKismetMathLibrary::DegAtan2(x_component, y_component); + }; + }; + // Called when the game starts or when spawned virtual void BeginPlay() override; @@ -85,4 +105,9 @@ protected: * Current health for character. */ int32 current_health; + + /** + * Last yaw. + */ + Yaw yaw; }; diff --git a/Source/PresidentsBrigade/PlayerPawn.cpp b/Source/PresidentsBrigade/PlayerPawn.cpp index 574a8f9..ffc7499 100755 --- a/Source/PresidentsBrigade/PlayerPawn.cpp +++ b/Source/PresidentsBrigade/PlayerPawn.cpp @@ -30,6 +30,8 @@ void APlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen Super::SetupPlayerInputComponent(PlayerInputComponent); PlayerInputComponent->BindAxis("MoveForward", this, &ABasePawn::handle_move_forward); PlayerInputComponent->BindAxis("MoveRight", this, &ABasePawn::handle_move_right); + PlayerInputComponent->BindAxis("YawXUpdate", this, &ABasePawn::update_yaw_x); + PlayerInputComponent->BindAxis("YawYUpdate", this, &ABasePawn::update_yaw_y); PlayerInputComponent->BindAction("Shoot", EInputEvent::IE_Pressed, this, &ABasePawn::shoot); PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Pressed, this, &APlayerPawn::boost); PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Released, this, &APlayerPawn::reset_boost); diff --git a/todo.txt b/todo.txt index 1c85886..ce1aa9e 100644 --- a/todo.txt +++ b/todo.txt @@ -10,7 +10,7 @@ xAdd enemy cars xComes from off screen xAttacks president car xAdd dash -Shoot from any direction +xShoot from any direction Shoot at continuous rate when holding shoot button Add local multiplayer Add netcode