Add shooting from any direction
This commit is contained in:
parent
0bf9105fcd
commit
48519be2d7
@ -101,6 +101,10 @@ DoubleClickTime=0.200000
|
|||||||
+AxisMappings=(AxisName="MoveRight",Scale=-1.000000,Key=A)
|
+AxisMappings=(AxisName="MoveRight",Scale=-1.000000,Key=A)
|
||||||
+AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=Gamepad_LeftY)
|
+AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=Gamepad_LeftY)
|
||||||
+AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=Gamepad_LeftX)
|
+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
|
DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks
|
||||||
-ConsoleKeys=Tilde
|
-ConsoleKeys=Tilde
|
||||||
+ConsoleKeys=Tilde
|
+ConsoleKeys=Tilde
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -96,28 +96,39 @@ void ABasePawn::Tick(float DeltaTime)
|
|||||||
|
|
||||||
void ABasePawn::handle_move_forward(float axis)
|
void ABasePawn::handle_move_forward(float axis)
|
||||||
{
|
{
|
||||||
FRotator rotation = Controller->GetControlRotation();
|
if (axis != 0)
|
||||||
FRotator yaw(0.0f, rotation.Yaw, 0.0f);
|
{
|
||||||
|
FVector forward = FRotationMatrix(FRotator()).GetUnitAxis(EAxis::X);
|
||||||
FVector forward = FRotationMatrix(yaw).GetUnitAxis(EAxis::X);
|
AddMovementInput(forward, axis);
|
||||||
AddMovementInput(forward, axis);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABasePawn::handle_move_right(float axis)
|
void ABasePawn::handle_move_right(float axis)
|
||||||
{
|
{
|
||||||
FRotator rotation = Controller->GetControlRotation();
|
if (axis != 0)
|
||||||
FRotator yaw(0.0f, rotation.Yaw, 0.0f);
|
{
|
||||||
|
FVector right = FRotationMatrix(FRotator()).GetUnitAxis(EAxis::Y);
|
||||||
|
AddMovementInput(right, axis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FVector right = FRotationMatrix(yaw).GetUnitAxis(EAxis::Y);
|
void ABasePawn::update_yaw_x(float x_component)
|
||||||
AddMovementInput(right, axis);
|
{
|
||||||
|
yaw.x_component = x_component;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ABasePawn::update_yaw_y(float y_component)
|
||||||
|
{
|
||||||
|
yaw.y_component = y_component;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABasePawn::shoot()
|
void ABasePawn::shoot()
|
||||||
{
|
{
|
||||||
FVector player_location = player_mesh->GetComponentLocation();
|
FVector player_location = player_mesh->GetComponentLocation();
|
||||||
FRotator rotation = Controller->GetControlRotation();
|
const float y = yaw.calculate_yaw();
|
||||||
FRotator yaw(0.0f, rotation.Yaw, 0.0f);
|
LogInfo(FString::Printf(TEXT("Raw yaw: %f"), y));
|
||||||
FVector forward = FRotationMatrix(yaw).GetUnitAxis(EAxis::X) * 100;
|
const FRotator rotator(0, y, 0);
|
||||||
|
FVector forward = FRotationMatrix(rotator).GetUnitAxis(EAxis::X) * 100;
|
||||||
|
|
||||||
FVector spawn_location = player_location + forward;
|
FVector spawn_location = player_location + forward;
|
||||||
FActorSpawnParameters spawnParameters;
|
FActorSpawnParameters spawnParameters;
|
||||||
@ -127,7 +138,7 @@ void ABasePawn::shoot()
|
|||||||
AActor* bullet = GetWorld()->SpawnActor<AActor>(
|
AActor* bullet = GetWorld()->SpawnActor<AActor>(
|
||||||
bullet_actor_class,
|
bullet_actor_class,
|
||||||
spawn_location,
|
spawn_location,
|
||||||
FRotator(0,0,0),
|
rotator,
|
||||||
spawnParameters
|
spawnParameters
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "GameFramework/Pawn.h"
|
#include "GameFramework/Pawn.h"
|
||||||
#include "Components/BoxComponent.h"
|
#include "Components/BoxComponent.h"
|
||||||
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
#include "BasePawn.generated.h"
|
#include "BasePawn.generated.h"
|
||||||
|
|
||||||
class UFloatingPawnMovement;
|
class UFloatingPawnMovement;
|
||||||
@ -24,9 +25,28 @@ public:
|
|||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
virtual void handle_move_right(float axis);
|
virtual void handle_move_right(float axis);
|
||||||
virtual void handle_move_forward(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 shoot();
|
||||||
virtual void handle_death();
|
virtual void handle_death();
|
||||||
protected:
|
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
|
// Called when the game starts or when spawned
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
@ -85,4 +105,9 @@ protected:
|
|||||||
* Current health for character.
|
* Current health for character.
|
||||||
*/
|
*/
|
||||||
int32 current_health;
|
int32 current_health;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last yaw.
|
||||||
|
*/
|
||||||
|
Yaw yaw;
|
||||||
};
|
};
|
||||||
|
@ -30,6 +30,8 @@ void APlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen
|
|||||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||||
PlayerInputComponent->BindAxis("MoveForward", this, &ABasePawn::handle_move_forward);
|
PlayerInputComponent->BindAxis("MoveForward", this, &ABasePawn::handle_move_forward);
|
||||||
PlayerInputComponent->BindAxis("MoveRight", this, &ABasePawn::handle_move_right);
|
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("Shoot", EInputEvent::IE_Pressed, this, &ABasePawn::shoot);
|
||||||
PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Pressed, this, &APlayerPawn::boost);
|
PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Pressed, this, &APlayerPawn::boost);
|
||||||
PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Released, this, &APlayerPawn::reset_boost);
|
PlayerInputComponent->BindAction("Boost", EInputEvent::IE_Released, this, &APlayerPawn::reset_boost);
|
||||||
|
2
todo.txt
2
todo.txt
@ -10,7 +10,7 @@ xAdd enemy cars
|
|||||||
xComes from off screen
|
xComes from off screen
|
||||||
xAttacks president car
|
xAttacks president car
|
||||||
xAdd dash
|
xAdd dash
|
||||||
Shoot from any direction
|
xShoot from any direction
|
||||||
Shoot at continuous rate when holding shoot button
|
Shoot at continuous rate when holding shoot button
|
||||||
Add local multiplayer
|
Add local multiplayer
|
||||||
Add netcode
|
Add netcode
|
||||||
|
Loading…
Reference in New Issue
Block a user