diff --git a/Source/FF/Private/FFCharacter.cpp b/Source/FF/Private/FFCharacter.cpp index 05eeed6..ba875fa 100644 --- a/Source/FF/Private/FFCharacter.cpp +++ b/Source/FF/Private/FFCharacter.cpp @@ -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); +} -} \ No newline at end of file +void AFFCharacter::MovementStrafe(float Value) +{ + AddMovementInput(GetActorRightVector(), Value); +} diff --git a/Source/FF/Private/FFCharacter.h b/Source/FF/Private/FFCharacter.h index 8c4e45b..b077368 100644 --- a/Source/FF/Private/FFCharacter.h +++ b/Source/FF/Private/FFCharacter.h @@ -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); }; diff --git a/Source/FF/Private/FFCharacterMovement.cpp b/Source/FF/Private/FFCharacterMovement.cpp index 4a0a083..b6ec350 100644 --- a/Source/FF/Private/FFCharacterMovement.cpp +++ b/Source/FF/Private/FFCharacterMovement.cpp @@ -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; } \ No newline at end of file diff --git a/Source/FF/Private/FFCharacterMovement.h b/Source/FF/Private/FFCharacterMovement.h index 8470054..ee0fbbb 100644 --- a/Source/FF/Private/FFCharacterMovement.h +++ b/Source/FF/Private/FFCharacterMovement.h @@ -12,4 +12,7 @@ UCLASS() class FF_API UFFCharacterMovement : public UCharacterMovementComponent { GENERATED_UCLASS_BODY() + +public: + bool DoJump(bool bReplayingMoves); }; diff --git a/Source/FF/Private/FFPlayerController.cpp b/Source/FF/Private/FFPlayerController.cpp index f313c76..eb385f0 100644 --- a/Source/FF/Private/FFPlayerController.cpp +++ b/Source/FF/Private/FFPlayerController.cpp @@ -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); @@ -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) @@ -75,6 +95,7 @@ void AFFPlayerController::SetPawn(APawn* NewPawn) AFFCharacter* AFFPlayerController::GetFFCharacter() { - // TODO: - return nullptr; + // for BPs + return FFCharacter; } + diff --git a/Source/FF/Private/FFPlayerController.h b/Source/FF/Private/FFPlayerController.h index a4bb0d3..3d73f7e 100644 --- a/Source/FF/Private/FFPlayerController.h +++ b/Source/FF/Private/FFPlayerController.h @@ -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)