Clean up dumb stuff
This commit is contained in:
		
							parent
							
								
									93926be25b
								
							
						
					
					
						commit
						0606deaccb
					
				| @ -4,6 +4,7 @@ | |||||||
| #include "BasePawn.h" | #include "BasePawn.h" | ||||||
| #include "Camera/CameraComponent.h" | #include "Camera/CameraComponent.h" | ||||||
| #include "Components/StaticMeshComponent.h" | #include "Components/StaticMeshComponent.h" | ||||||
|  | #include "GameFramework/FloatingPawnMovement.h" | ||||||
| 
 | 
 | ||||||
| // Sets default values
 | // Sets default values
 | ||||||
| ABasePawn::ABasePawn(const FObjectInitializer &object_initializer):  | ABasePawn::ABasePawn(const FObjectInitializer &object_initializer):  | ||||||
| @ -22,11 +23,6 @@ ABasePawn::ABasePawn(const FObjectInitializer &object_initializer): | |||||||
| 	movement_component->UpdatedComponent = player_mesh; | 	movement_component->UpdatedComponent = player_mesh; | ||||||
| 
 | 
 | ||||||
| 	PrimaryActorTick.bCanEverTick = true; | 	PrimaryActorTick.bCanEverTick = true; | ||||||
| 
 |  | ||||||
| 	// Set defaults.
 |  | ||||||
| 	accel_max_time = 0.25; |  | ||||||
| 	horizontal_speed_max = 100; |  | ||||||
| 	vertical_speed_max = 100; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Called when the game starts or when spawned
 | // Called when the game starts or when spawned
 | ||||||
| @ -45,35 +41,12 @@ UPawnMovementComponent* ABasePawn::GetMovementComponent() const | |||||||
| void ABasePawn::Tick(float DeltaTime) | void ABasePawn::Tick(float DeltaTime) | ||||||
| { | { | ||||||
| 	Super::Tick(DeltaTime); | 	Super::Tick(DeltaTime); | ||||||
| 
 |  | ||||||
| 	// Move the player.
 |  | ||||||
| 	//vertical_speed = vertical_accel.update(DeltaTime);
 |  | ||||||
| 	//horizontal_speed = horizontal_accel.update(DeltaTime);
 |  | ||||||
| 
 |  | ||||||
| 	//// "X" is up, "Y" is right.
 |  | ||||||
| 	//const FVector location = player_mesh->GetComponentLocation();
 |  | ||||||
| 	//const float new_vertical = (DeltaTime * vertical_speed) + location.X;
 |  | ||||||
| 	//const float new_horizontal = (DeltaTime * horizontal_speed) + location.Y;
 |  | ||||||
| 	//player_mesh->SetWorldLocation(FVector(new_vertical, new_horizontal, location.Z));
 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Called to bind functionality to input
 | // Called to bind functionality to input
 | ||||||
| void ABasePawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) | void ABasePawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) | ||||||
| { | { | ||||||
| 	Super::SetupPlayerInputComponent(PlayerInputComponent); | 	Super::SetupPlayerInputComponent(PlayerInputComponent); | ||||||
| 
 |  | ||||||
| 	//PlayerInputComponent->BindAction<FMovementDelegate>("MoveUp", EInputEvent::IE_Pressed, this, &ABasePawn::handle_move_input, movement_t::UP, 1);
 |  | ||||||
| 	//PlayerInputComponent->BindAction<FMovementDelegate>("MoveUp", EInputEvent::IE_Released, this, &ABasePawn::handle_move_input, movement_t::UP, 0);
 |  | ||||||
| 
 |  | ||||||
| 	//PlayerInputComponent->BindAction<FMovementDelegate>("MoveDown", EInputEvent::IE_Pressed, this, &ABasePawn::handle_move_input, movement_t::DOWN, -1);
 |  | ||||||
| 	//PlayerInputComponent->BindAction<FMovementDelegate>("MoveDown", EInputEvent::IE_Released, this, &ABasePawn::handle_move_input, movement_t::DOWN, 0);
 |  | ||||||
| 
 |  | ||||||
| 	//PlayerInputComponent->BindAction<FMovementDelegate>("MoveRight", EInputEvent::IE_Pressed, this, &ABasePawn::handle_move_input, movement_t::RIGHT, 1);
 |  | ||||||
| 	//PlayerInputComponent->BindAction<FMovementDelegate>("MoveRight", EInputEvent::IE_Released, this, &ABasePawn::handle_move_input, movement_t::RIGHT, 0);
 |  | ||||||
| 
 |  | ||||||
| 	//PlayerInputComponent->BindAction<FMovementDelegate>("MoveLeft", EInputEvent::IE_Pressed, this, &ABasePawn::handle_move_input, movement_t::LEFT, -1);
 |  | ||||||
| 	//PlayerInputComponent->BindAction<FMovementDelegate>("MoveLeft", EInputEvent::IE_Released, this, &ABasePawn::handle_move_input, movement_t::LEFT, 0);
 |  | ||||||
| 
 |  | ||||||
| 	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); | ||||||
| } | } | ||||||
| @ -95,28 +68,3 @@ void ABasePawn::handle_move_right(float axis) | |||||||
| 	FVector right = FRotationMatrix(yaw).GetUnitAxis(EAxis::Y); | 	FVector right = FRotationMatrix(yaw).GetUnitAxis(EAxis::Y); | ||||||
| 	AddMovementInput(right, axis); | 	AddMovementInput(right, axis); | ||||||
| } | } | ||||||
| //void ABasePawn::handle_move_input(const movement_t move_type, const int direction)
 |  | ||||||
| //{
 |  | ||||||
| //	if (move_type == movement_t::UP || move_type == movement_t::DOWN)
 |  | ||||||
| //	{
 |  | ||||||
| //		// Prevent two vertical inputs entered at the same time.
 |  | ||||||
| //		if (vertical_accel.end != 0 && direction != 0)
 |  | ||||||
| //		{
 |  | ||||||
| //			return;
 |  | ||||||
| //		}
 |  | ||||||
| //
 |  | ||||||
| //		const float new_speed = direction * vertical_speed_max;
 |  | ||||||
| //		vertical_accel.set(vertical_speed, new_speed, accel_max_time);
 |  | ||||||
| //	}
 |  | ||||||
| //	else
 |  | ||||||
| //	{
 |  | ||||||
| //		// Prevent two horizontal inputs entered at the same time.
 |  | ||||||
| //		if (horizontal_accel.end != 0 && direction != 0)
 |  | ||||||
| //		{
 |  | ||||||
| //			return;
 |  | ||||||
| //		}
 |  | ||||||
| //
 |  | ||||||
| //		const float new_speed = direction * horizontal_speed_max;
 |  | ||||||
| //		horizontal_accel.set(horizontal_speed, new_speed, accel_max_time);
 |  | ||||||
| //	}
 |  | ||||||
| //}
 |  | ||||||
|  | |||||||
| @ -4,20 +4,10 @@ | |||||||
| 
 | 
 | ||||||
| #include "CoreMinimal.h" | #include "CoreMinimal.h" | ||||||
| #include "GameFramework/Pawn.h" | #include "GameFramework/Pawn.h" | ||||||
| #include "Kismet/KismetMathLibrary.h" |  | ||||||
| #include "GameFramework/CharacterMovementComponent.h" |  | ||||||
| #include "GameFramework/FloatingPawnMovement.h" |  | ||||||
| #include "BasePawn.generated.h" | #include "BasePawn.generated.h" | ||||||
| 
 | 
 | ||||||
| class UCameraComponent; | class UCameraComponent; | ||||||
| 
 | class UFloatingPawnMovement; | ||||||
| //enum movement_t : uint8
 |  | ||||||
| //{
 |  | ||||||
| //	UP,
 |  | ||||||
| //	DOWN,
 |  | ||||||
| //	LEFT,
 |  | ||||||
| //	RIGHT
 |  | ||||||
| //};
 |  | ||||||
| 
 | 
 | ||||||
| UCLASS() | UCLASS() | ||||||
| class PRESIDENTSBRIGADE_API ABasePawn : public APawn | class PRESIDENTSBRIGADE_API ABasePawn : public APawn | ||||||
| @ -48,60 +38,9 @@ protected: | |||||||
| 	UPROPERTY(EditAnywhere, Category="Player") | 	UPROPERTY(EditAnywhere, Category="Player") | ||||||
| 	UFloatingPawnMovement* movement_component; | 	UFloatingPawnMovement* movement_component; | ||||||
| 
 | 
 | ||||||
| 	// Accel max time.
 |  | ||||||
| 	UPROPERTY(EditDefaultsOnly, Category="Gameplay") |  | ||||||
| 	float accel_max_time; |  | ||||||
| 
 |  | ||||||
| 	// Maximum horizontal speed.
 |  | ||||||
| 	UPROPERTY(EditDefaultsOnly, Category="Gameplay") |  | ||||||
| 	float horizontal_speed_max; |  | ||||||
| 
 |  | ||||||
| 	// Maximum vertical speed.
 |  | ||||||
| 	UPROPERTY(EditDefaultsOnly, Category="Gameplay") |  | ||||||
| 	float vertical_speed_max; |  | ||||||
| 
 |  | ||||||
| private:	 | private:	 | ||||||
| 	struct AccelerationAnim |  | ||||||
| 	{ |  | ||||||
| 		float start; |  | ||||||
| 		float end; |  | ||||||
| 		float max_time; |  | ||||||
| 
 |  | ||||||
| 		float time_elapsed; |  | ||||||
| 
 |  | ||||||
| 		void set(float _start, float _end, float _max_time) |  | ||||||
| 		{ |  | ||||||
| 			start = _start; |  | ||||||
| 			end = _end; |  | ||||||
| 			max_time = _max_time; |  | ||||||
| 			time_elapsed = 0; |  | ||||||
| 		}; |  | ||||||
| 
 |  | ||||||
| 		float update(const float delta_time) |  | ||||||
| 		{ |  | ||||||
| 			float percentage = time_elapsed / max_time; |  | ||||||
| 
 |  | ||||||
| 			// Animation is complete.
 |  | ||||||
| 			if (time_elapsed > max_time) |  | ||||||
| 			{ |  | ||||||
| 				percentage = 1; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			time_elapsed += delta_time; |  | ||||||
| 			return UKismetMathLibrary::Lerp(start, end, percentage); |  | ||||||
| 		}; |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	USceneComponent* root_component; | 	USceneComponent* root_component; | ||||||
| 
 | 
 | ||||||
| //	DECLARE_DELEGATE_TwoParams(FMovementDelegate, const movement_t, const int);
 |  | ||||||
| //	void handle_move_input(const movement_t move_type, const int direction);
 |  | ||||||
| 	void handle_move_right(float axis); | 	void handle_move_right(float axis); | ||||||
| 	void handle_move_forward(float axis); | 	void handle_move_forward(float axis); | ||||||
| 
 |  | ||||||
| 	float horizontal_speed; |  | ||||||
| 	float vertical_speed; |  | ||||||
| 
 |  | ||||||
| 	AccelerationAnim horizontal_accel; |  | ||||||
| 	AccelerationAnim vertical_accel; |  | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -1,201 +0,0 @@ | |||||||
| // Fill out your copyright notice in the Description page of Project Settings.
 |  | ||||||
| #include "MyDefaultPawn.h" |  | ||||||
| 
 |  | ||||||
| #include "UObject/ConstructorHelpers.h" |  | ||||||
| #include "Engine/World.h" |  | ||||||
| #include "Components/StaticMeshComponent.h" |  | ||||||
| #include "GameFramework/PlayerController.h" |  | ||||||
| #include "Engine/CollisionProfile.h" |  | ||||||
| #include "Engine/StaticMesh.h" |  | ||||||
| #include "Components/SphereComponent.h" |  | ||||||
| #include "GameFramework/PawnMovementComponent.h" |  | ||||||
| #include "GameFramework/FloatingPawnMovement.h" |  | ||||||
| #include "GameFramework/CharacterMovementComponent.h" |  | ||||||
| #include "GameFramework/PlayerInput.h" |  | ||||||
| 
 |  | ||||||
| FName AMyDefaultPawn::MovementComponentName(TEXT("MovementComponent0")); |  | ||||||
| FName AMyDefaultPawn::CollisionComponentName(TEXT("CollisionComponent0")); |  | ||||||
| FName AMyDefaultPawn::MeshComponentName(TEXT("MeshComponent0")); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| AMyDefaultPawn::AMyDefaultPawn(const FObjectInitializer& ObjectInitializer) : APawn(ObjectInitializer) |  | ||||||
| { |  | ||||||
| 	SetCanBeDamaged(true); |  | ||||||
| 
 |  | ||||||
| 	SetRemoteRoleForBackwardsCompat(ROLE_SimulatedProxy); |  | ||||||
| 	bReplicates = true; |  | ||||||
| 	NetPriority = 3.0f; |  | ||||||
| 
 |  | ||||||
| 	BaseEyeHeight = 0.0f; |  | ||||||
| 	bCollideWhenPlacing = false; |  | ||||||
| 	SpawnCollisionHandlingMethod = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; |  | ||||||
| 
 |  | ||||||
| 	CollisionComponent = CreateDefaultSubobject<USphereComponent>(AMyDefaultPawn::CollisionComponentName); |  | ||||||
| 	CollisionComponent->InitSphereRadius(35.0f); |  | ||||||
| 	CollisionComponent->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName); |  | ||||||
| 
 |  | ||||||
| 	CollisionComponent->CanCharacterStepUpOn = ECB_No; |  | ||||||
| 	CollisionComponent->SetShouldUpdatePhysicsVolume(true); |  | ||||||
| 	CollisionComponent->SetCanEverAffectNavigation(false); |  | ||||||
| 	CollisionComponent->bDynamicObstacle = true; |  | ||||||
| 
 |  | ||||||
| 	RootComponent = CollisionComponent; |  | ||||||
| 
 |  | ||||||
| 	MovementComponent = CreateDefaultSubobject<UPawnMovementComponent, UCharacterMovementComponent>(AMyDefaultPawn::MovementComponentName); |  | ||||||
| 	MovementComponent->UpdatedComponent = CollisionComponent; |  | ||||||
| 
 |  | ||||||
| 	// Structure to hold one-time initialization
 |  | ||||||
| 	struct FConstructorStatics |  | ||||||
| 	{ |  | ||||||
| 		ConstructorHelpers::FObjectFinder<UStaticMesh> SphereMesh; |  | ||||||
| 		FConstructorStatics() |  | ||||||
| 			: SphereMesh(TEXT("/Engine/EngineMeshes/Sphere")) {} |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	static FConstructorStatics ConstructorStatics; |  | ||||||
| 
 |  | ||||||
| 	MeshComponent = CreateOptionalDefaultSubobject<UStaticMeshComponent>(AMyDefaultPawn::MeshComponentName); |  | ||||||
| 	if (MeshComponent) |  | ||||||
| 	{ |  | ||||||
| 		MeshComponent->SetStaticMesh(ConstructorStatics.SphereMesh.Object); |  | ||||||
| 		MeshComponent->AlwaysLoadOnClient = true; |  | ||||||
| 		MeshComponent->AlwaysLoadOnServer = true; |  | ||||||
| 		MeshComponent->bOwnerNoSee = true; |  | ||||||
| 		MeshComponent->bCastDynamicShadow = true; |  | ||||||
| 		MeshComponent->bAffectDynamicIndirectLighting = false; |  | ||||||
| 		MeshComponent->bAffectDistanceFieldLighting = false; |  | ||||||
| 		MeshComponent->bVisibleInRayTracing = false; |  | ||||||
| 		MeshComponent->PrimaryComponentTick.TickGroup = TG_PrePhysics; |  | ||||||
| 		MeshComponent->SetupAttachment(RootComponent); |  | ||||||
| 		MeshComponent->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName); |  | ||||||
| 		const float Scale = CollisionComponent->GetUnscaledSphereRadius() / 160.f; // @TODO: hardcoding known size of EngineMeshes.Sphere. Should use a unit sphere instead.
 |  | ||||||
| 		MeshComponent->SetRelativeScale3D(FVector(Scale)); |  | ||||||
| 		MeshComponent->SetGenerateOverlapEvents(false); |  | ||||||
| 		MeshComponent->SetCanEverAffectNavigation(false); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// This is the default pawn class, we want to have it be able to move out of the box.
 |  | ||||||
| 	bAddDefaultMovementBindings = true; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void InitializeDefaultPawnInputBindings() |  | ||||||
| { |  | ||||||
| 	static bool bBindingsAdded = false; |  | ||||||
| 	if (!bBindingsAdded) |  | ||||||
| 	{ |  | ||||||
| 		bBindingsAdded = true; |  | ||||||
| 
 |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveForward", EKeys::W, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveForward", EKeys::S, -1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveForward", EKeys::Up, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveForward", EKeys::Down, -1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveForward", EKeys::Gamepad_LeftY, 1.f)); |  | ||||||
| 
 |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveRight", EKeys::A, -1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveRight", EKeys::D, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveRight", EKeys::Gamepad_LeftX, 1.f)); |  | ||||||
| 
 |  | ||||||
| 		// HACK: Android controller bindings in ini files seem to not work
 |  | ||||||
| 		//  Direct overrides here some to work
 |  | ||||||
| #if !PLATFORM_ANDROID |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::Gamepad_LeftThumbstick, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::Gamepad_RightThumbstick, -1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::Gamepad_FaceButton_Bottom, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::LeftControl, -1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::SpaceBar, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::C, -1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::E, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::Q, -1.f)); |  | ||||||
| #else |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::Gamepad_LeftTriggerAxis, -0.5f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_MoveUp", EKeys::Gamepad_RightTriggerAxis, 0.5f)); |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_TurnRate", EKeys::Gamepad_RightX, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_TurnRate", EKeys::Left, -1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_TurnRate", EKeys::Right, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_Turn", EKeys::MouseX, 1.f)); |  | ||||||
| 
 |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_LookUpRate", EKeys::Gamepad_RightY, 1.f)); |  | ||||||
| 		UPlayerInput::AddEngineDefinedAxisMapping(FInputAxisKeyMapping("DefaultPawn_LookUp", EKeys::MouseY, -1.f)); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMyDefaultPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) |  | ||||||
| { |  | ||||||
| 	check(PlayerInputComponent); |  | ||||||
| 
 |  | ||||||
| 	if (bAddDefaultMovementBindings) |  | ||||||
| 	{ |  | ||||||
| 		InitializeDefaultPawnInputBindings(); |  | ||||||
| 
 |  | ||||||
| 		PlayerInputComponent->BindAxis("DefaultPawn_MoveForward", this, &AMyDefaultPawn::MoveForward); |  | ||||||
| 		PlayerInputComponent->BindAxis("DefaultPawn_MoveRight", this, &AMyDefaultPawn::MoveRight); |  | ||||||
| 		PlayerInputComponent->BindAxis("DefaultPawn_MoveUp", this, &AMyDefaultPawn::MoveUp_World); |  | ||||||
| 		PlayerInputComponent->BindAxis("DefaultPawn_Turn", this, &AMyDefaultPawn::AddControllerYawInput); |  | ||||||
| 		PlayerInputComponent->BindAxis("DefaultPawn_TurnRate", this, &AMyDefaultPawn::TurnAtRate); |  | ||||||
| 		PlayerInputComponent->BindAxis("DefaultPawn_LookUp", this, &AMyDefaultPawn::AddControllerPitchInput); |  | ||||||
| 		PlayerInputComponent->BindAxis("DefaultPawn_LookUpRate", this, &AMyDefaultPawn::LookUpAtRate); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMyDefaultPawn::UpdateNavigationRelevance() |  | ||||||
| { |  | ||||||
| 	if (CollisionComponent) |  | ||||||
| 	{ |  | ||||||
| 		CollisionComponent->SetCanEverAffectNavigation(bCanAffectNavigationGeneration); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMyDefaultPawn::MoveRight(float Val) |  | ||||||
| { |  | ||||||
| 	if (Val != 0.f) |  | ||||||
| 	{ |  | ||||||
| 		if (Controller) |  | ||||||
| 		{ |  | ||||||
| 			FRotator const ControlSpaceRot = Controller->GetControlRotation(); |  | ||||||
| 
 |  | ||||||
| 			// transform to world space and add it
 |  | ||||||
| 			AddMovementInput(FRotationMatrix(ControlSpaceRot).GetScaledAxis(EAxis::Y), Val); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMyDefaultPawn::MoveForward(float Val) |  | ||||||
| { |  | ||||||
| 	if (Val != 0.f) |  | ||||||
| 	{ |  | ||||||
| 		if (Controller) |  | ||||||
| 		{ |  | ||||||
| 			FRotator const ControlSpaceRot = Controller->GetControlRotation(); |  | ||||||
| 
 |  | ||||||
| 			// transform to world space and add it
 |  | ||||||
| 			AddMovementInput(FRotationMatrix(ControlSpaceRot).GetScaledAxis(EAxis::X), Val); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMyDefaultPawn::MoveUp_World(float Val) |  | ||||||
| { |  | ||||||
| 	if (Val != 0.f) |  | ||||||
| 	{ |  | ||||||
| 		AddMovementInput(FVector::UpVector, Val); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMyDefaultPawn::TurnAtRate(float Rate) |  | ||||||
| { |  | ||||||
| 	// calculate delta for this frame from the rate information
 |  | ||||||
| 	AddControllerYawInput(Rate *  GetWorld()->GetDeltaSeconds() * CustomTimeDilation); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void AMyDefaultPawn::LookUpAtRate(float Rate) |  | ||||||
| { |  | ||||||
| 	// calculate delta for this frame from the rate information
 |  | ||||||
| 	AddControllerPitchInput(Rate *  GetWorld()->GetDeltaSeconds() * CustomTimeDilation); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| UPawnMovementComponent* AMyDefaultPawn::GetMovementComponent() const |  | ||||||
| { |  | ||||||
| 	return MovementComponent; |  | ||||||
| } |  | ||||||
| @ -1,102 +0,0 @@ | |||||||
| // Fill out your copyright notice in the Description page of Project Settings.
 |  | ||||||
| #pragma once |  | ||||||
| 
 |  | ||||||
| #include "CoreMinimal.h" |  | ||||||
| #include "GameFramework/Pawn.h" |  | ||||||
| #include "MyDefaultPawn.generated.h" |  | ||||||
| 
 |  | ||||||
| class UInputComponent; |  | ||||||
| class UPawnMovementComponent; |  | ||||||
| class USphereComponent; |  | ||||||
| class UStaticMeshComponent; |  | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  *  |  | ||||||
|  */ |  | ||||||
| UCLASS(config = Game, Blueprintable, BlueprintType) |  | ||||||
| class PRESIDENTSBRIGADE_API AMyDefaultPawn : public APawn |  | ||||||
| { |  | ||||||
| 	GENERATED_BODY() |  | ||||||
| 
 |  | ||||||
| 	AMyDefaultPawn(const FObjectInitializer& ObjectInitializer); |  | ||||||
| 
 |  | ||||||
| 	// Begin Pawn overrides
 |  | ||||||
| 	virtual UPawnMovementComponent* GetMovementComponent() const override; |  | ||||||
| 	virtual void SetupPlayerInputComponent(UInputComponent* InInputComponent) override; |  | ||||||
| 	virtual void UpdateNavigationRelevance() override; |  | ||||||
| 
 |  | ||||||
| 	/**
 |  | ||||||
| 	 * Input callback to move forward in local space (or backward if Val is negative). |  | ||||||
| 	 * @param Val Amount of movement in the forward direction (or backward if negative). |  | ||||||
| 	 * @see APawn::AddMovementInput() |  | ||||||
| 	 */ |  | ||||||
| 	UFUNCTION(BlueprintCallable, Category = "Pawn") |  | ||||||
| 		virtual void MoveForward(float Val); |  | ||||||
| 
 |  | ||||||
| 	/**
 |  | ||||||
| 	 * Input callback to strafe right in local space (or left if Val is negative). |  | ||||||
| 	 * @param Val Amount of movement in the right direction (or left if negative). |  | ||||||
| 	 * @see APawn::AddMovementInput() |  | ||||||
| 	 */ |  | ||||||
| 	UFUNCTION(BlueprintCallable, Category = "Pawn") |  | ||||||
| 		virtual void MoveRight(float Val); |  | ||||||
| 
 |  | ||||||
| 	/**
 |  | ||||||
| 	 * Input callback to move up in world space (or down if Val is negative). |  | ||||||
| 	 * @param Val Amount of movement in the world up direction (or down if negative). |  | ||||||
| 	 * @see APawn::AddMovementInput() |  | ||||||
| 	 */ |  | ||||||
| 	UFUNCTION(BlueprintCallable, Category = "Pawn") |  | ||||||
| 		virtual void MoveUp_World(float Val); |  | ||||||
| 
 |  | ||||||
| 	/**
 |  | ||||||
| 	 * Called via input to turn at a given rate. |  | ||||||
| 	 * @param Rate	This is a normalized rate, i.e. 1.0 means 100% of desired turn rate |  | ||||||
| 	 */ |  | ||||||
| 	UFUNCTION(BlueprintCallable, Category = "Pawn") |  | ||||||
| 		virtual void TurnAtRate(float Rate); |  | ||||||
| 
 |  | ||||||
| 	/**
 |  | ||||||
| 	* Called via input to look up at a given rate (or down if Rate is negative). |  | ||||||
| 	* @param Rate	This is a normalized rate, i.e. 1.0 means 100% of desired turn rate |  | ||||||
| 	*/ |  | ||||||
| 	UFUNCTION(BlueprintCallable, Category = "Pawn") |  | ||||||
| 		virtual void LookUpAtRate(float Rate); |  | ||||||
| 
 |  | ||||||
| public: |  | ||||||
| 	/** Name of the MovementComponent.  Use this name if you want to use a different class (with ObjectInitializer.SetDefaultSubobjectClass). */ |  | ||||||
| 	static FName MovementComponentName; |  | ||||||
| 
 |  | ||||||
| protected: |  | ||||||
| 	/** DefaultPawn movement component */ |  | ||||||
| 	UPROPERTY(Category = Pawn, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true")) |  | ||||||
| 		UPawnMovementComponent* MovementComponent; |  | ||||||
| 
 |  | ||||||
| public: |  | ||||||
| 	/** Name of the CollisionComponent. */ |  | ||||||
| 	static FName CollisionComponentName; |  | ||||||
| 
 |  | ||||||
| private: |  | ||||||
| 	/** DefaultPawn collision component */ |  | ||||||
| 	UPROPERTY(Category = Pawn, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true")) |  | ||||||
| 		USphereComponent* CollisionComponent; |  | ||||||
| public: |  | ||||||
| 
 |  | ||||||
| 	/** Name of the MeshComponent. Use this name if you want to prevent creation of the component (with ObjectInitializer.DoNotCreateDefaultSubobject). */ |  | ||||||
| 	static FName MeshComponentName; |  | ||||||
| 
 |  | ||||||
| private: |  | ||||||
| 	/** The mesh associated with this Pawn. */ |  | ||||||
| 	UPROPERTY(Category = Pawn, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true")) |  | ||||||
| 		UStaticMeshComponent* MeshComponent; |  | ||||||
| public:  |  | ||||||
| 
 |  | ||||||
| 	/** If true, adds default input bindings for movement and camera look. */ |  | ||||||
| 	UPROPERTY(Category = Pawn, EditAnywhere, BlueprintReadOnly) |  | ||||||
| 		uint32 bAddDefaultMovementBindings : 1; |  | ||||||
| 
 |  | ||||||
| 	/** Returns CollisionComponent subobject **/ |  | ||||||
| 	USphereComponent* GetCollisionComponent() const { return CollisionComponent; } |  | ||||||
| 	/** Returns MeshComponent subobject **/ |  | ||||||
| 	UStaticMeshComponent* GetMeshComponent() const { return MeshComponent; } |  | ||||||
| }; |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Sara Montecino
						Sara Montecino