Navigation Menu

Skip to content

Commit

Permalink
wireup inputs and add jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
DexterHaslem committed Mar 29, 2017
1 parent cc2f669 commit 2a4092c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 19 deletions.
18 changes: 17 additions & 1 deletion Source/FF/Private/FFCharacter.cpp
Expand Up @@ -31,5 +31,21 @@ void AFFCharacter::BeginPlay()
void AFFCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

// movement section
// NOTE: non-axis movement is triggered from controller which checks 0 value locks
// its kind of a round-about way to handle input:
// 1 - controller bindings
// 2 - character adds movement input value
// 3 - character movement triggered
// mouse skips right to adding input value
void AFFCharacter::MovementForwardBack(float Value)
{
AddMovementInput(GetActorForwardVector(), Value);
}

}
void AFFCharacter::MovementStrafe(float Value)
{
AddMovementInput(GetActorRightVector(), Value);
}
4 changes: 4 additions & 0 deletions Source/FF/Private/FFCharacter.h
Expand Up @@ -33,4 +33,8 @@ class AFFCharacter : public ACharacter
virtual void Tick(float DeltaTime) override;

FORCEINLINE class UCameraComponent* GetFirstPersonCameraComponent() const { return CameraComponent; }

// Movement commands from input
void MovementStrafe(float Value);
void MovementForwardBack(float Value);
};
38 changes: 30 additions & 8 deletions Source/FF/Private/FFCharacterMovement.cpp
Expand Up @@ -13,17 +13,39 @@ UFFCharacterMovement::UFFCharacterMovement(const class FObjectInitializer& Objec
// q2 style double jumps
// rampslides and sharks
// would rather simplify and just make the movement fast and crisp to start with,
// which surprisingly the default networked movement can do OK at
// which surprisingly the default networked movement can do OK at .
// if someone was so inclined to do so, this class would be the place to do it as it can handle
// the frame by frame movement calculations and pmove

MaxWalkSpeed = 1105.0f;
AirControl = 0.65f;
GroundFriction = 11.0f;
BrakingFriction = 12.0f;
MaxWalkSpeed = 1000.0f;
AirControl = 0.75f;
GroundFriction = 4.0f;
BrakingFriction = 10.0f;
BrakingFrictionFactor = 3;
GravityScale = 1.0f;
JumpZVelocity = 350.0f;
BrakingDecelerationFalling = 1.0f;

JumpZVelocity = 800.0f;

MaxAcceleration = 3500.0f;
Mass = 110.0f;
// todo: non-accel based strafe movement etc
MaxAcceleration = 6500.0f;

// verdict is out on this one
NetworkSmoothingMode = ENetworkSmoothingMode::Exponential;
}

bool UFFCharacterMovement::DoJump(bool bReplayingMoves)
{
if (CharacterOwner && CharacterOwner->CanJump())
{
// Don't jump if we can't move up/down.
if (!bConstrainToPlane || FMath::Abs(PlaneConstraintNormal.Z) != 1.f)
{
Velocity.Z = JumpZVelocity;
SetMovementMode(MOVE_Falling);
return true;
}
}

return false;
}
3 changes: 3 additions & 0 deletions Source/FF/Private/FFCharacterMovement.h
Expand Up @@ -12,4 +12,7 @@ UCLASS()
class FF_API UFFCharacterMovement : public UCharacterMovementComponent
{
GENERATED_UCLASS_BODY()

public:
bool DoJump(bool bReplayingMoves);
};
41 changes: 31 additions & 10 deletions Source/FF/Private/FFPlayerController.cpp
Expand Up @@ -11,8 +11,8 @@ void AFFPlayerController::SetupInputComponent()
Super::SetupInputComponent();

// TODO: the base ACharacter jump handling kinda stinks
//InputComponent->BindAction("Jump", IE_Pressed, this, &AFFPlayerController::InputJump);
//InputComponent->BindAction("Jump", IE_Released, this, &AFFPlayerController::InputStopJumping);
InputComponent->BindAction("Jump", IE_Pressed, this, &AFFPlayerController::JumpPressed);
InputComponent->BindAction("Jump", IE_Released, this, &AFFPlayerController::JumpReleased);
InputComponent->BindAxis("Forward", this, &AFFPlayerController::Forward);
InputComponent->BindAxis("Strafe", this, &AFFPlayerController::Strafe);
InputComponent->BindAxis("LookX", this, &AFFPlayerController::LookX);
Expand All @@ -21,34 +21,54 @@ void AFFPlayerController::SetupInputComponent()
MouseSensitivityRate = 150.0f;
}

// bind axis has nonconst :-(

// ReSharper disable once CppMemberFunctionMayBeConst
void AFFPlayerController::Forward(float Value)
{
if (Value != 0.0f)
{
// add movement in that direction
//AddMovementInput(GetActorForwardVector(), Value);
FFCharacter->MovementForwardBack(Value);
}
}

// ReSharper disable once CppMemberFunctionMayBeConst
void AFFPlayerController::Strafe(float Value)
{
if (Value != 0.0f)
{
// add movement in that direction
//AddMovementInput(GetActorRightVector(), Value);
FFCharacter->MovementStrafe(Value);
}
}

void AFFPlayerController::LookX(float Rate)
{
// calculate delta for this frame from the rate information
//AddControllerYawInput(Rate * MouseSensitivityRate * GetWorld()->GetDeltaSeconds());
AddYawInput(Rate * MouseSensitivityRate * GetWorld()->GetDeltaSeconds());
}

void AFFPlayerController::LookY(float Rate)
{
// calculate delta for this frame from the rate information
//AddControllerPitchInput(Rate * MouseSensitivityRate * GetWorld()->GetDeltaSeconds());
AddPitchInput(Rate * MouseSensitivityRate * GetWorld()->GetDeltaSeconds());
}

void AFFPlayerController::JumpPressed()
{
if (FFCharacter != NULL && !IsMoveInputIgnored())
{
//FFCharacter->bPressedJump = true;
FFCharacter->Jump();
}
}

void AFFPlayerController::JumpReleased()
{
if (FFCharacter)
{
//FFCharacter->bPressedJump = false;
FFCharacter->StopJumping();
}
}

void AFFPlayerController::SetPawn(APawn* NewPawn)
Expand All @@ -75,6 +95,7 @@ void AFFPlayerController::SetPawn(APawn* NewPawn)

AFFCharacter* AFFPlayerController::GetFFCharacter()
{
// TODO:
return nullptr;
// for BPs
return FFCharacter;
}

2 changes: 2 additions & 0 deletions Source/FF/Private/FFPlayerController.h
Expand Up @@ -23,6 +23,8 @@ class AFFPlayerController : public APlayerController
void Strafe(float Val);
void LookX(float Rate);
void LookY(float Rate);
void JumpPressed();
void JumpReleased();

public:
UPROPERTY(BlueprintReadOnly, GlobalConfig, Category = Camera)
Expand Down

0 comments on commit 2a4092c

Please sign in to comment.