diff --git a/SwordNGun/Content/Characters/Protagonist/BP_NewProtag.uasset b/SwordNGun/Content/Characters/Protagonist/BP_NewProtag.uasset index e91bd71..5089b32 100644 --- a/SwordNGun/Content/Characters/Protagonist/BP_NewProtag.uasset +++ b/SwordNGun/Content/Characters/Protagonist/BP_NewProtag.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:039d1630c89642de057a33b027d97d374d4d8a3fe07310c343ec76c8308c5d93 -size 121177 +oid sha256:32c3b487afded73f772bbc4d2afbd62fa4de14a0c10c9b1a926717a569490f61 +size 120474 diff --git a/SwordNGun/Content/Maps/MovementTest.umap b/SwordNGun/Content/Maps/MovementTest.umap index 94856af..51bac59 100644 --- a/SwordNGun/Content/Maps/MovementTest.umap +++ b/SwordNGun/Content/Maps/MovementTest.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:74fd15f88e1e5f8e8b8b5167d2749364d7fbec56235c3868759b2d819081bd22 +oid sha256:648e3d439ffcd3e0dd0650512a2a99641ee7e7b02c6a85dcdccbf2f3713a99b9 size 949560 diff --git a/SwordNGun/Source/SwordNGun/Private/Characters/SNGCharacterBase.cpp b/SwordNGun/Source/SwordNGun/Private/Characters/SNGCharacterBase.cpp index af4f60a..7f5fe67 100644 --- a/SwordNGun/Source/SwordNGun/Private/Characters/SNGCharacterBase.cpp +++ b/SwordNGun/Source/SwordNGun/Private/Characters/SNGCharacterBase.cpp @@ -205,11 +205,13 @@ void ASNGCharacterBase::Tick(float DeltaTime) // Debug if(CharacterMovementDebug) { + float LateralSpeed = GetVelocity().Size2D(); FVector StartPos(GetActorLocation().X, GetActorLocation().Y, GetActorLocation().Z - GetCapsuleComponent()->GetScaledCapsuleHalfHeight()); FVector ActorForward = UKismetMathLibrary::GetForwardVector(GetActorRotation()); - DrawDebugDirectionalArrow(GetWorld(), StartPos, StartPos + (ActorForward * 100.0f), + DrawDebugDirectionalArrow(GetWorld(), + StartPos, StartPos + (ActorForward * ((LateralSpeed / GetCharacterMovement()->MaxWalkSpeed) * 100.0f)), 10.0f, FColor::Blue, false, -1.0f, 0, 2.0f); FVector CurrInputDirection = GetInputAsWorldDirection(); @@ -220,7 +222,7 @@ void ASNGCharacterBase::Tick(float DeltaTime) FString DebugMsg = FString::Printf(TEXT("MaxWalkSpeed: %f"), GetCharacterMovement()->MaxWalkSpeed); GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Magenta, DebugMsg); - float LateralSpeed = GetVelocity().Size2D(); + DebugMsg = FString::Printf(TEXT("LateralSpeed: %f"), LateralSpeed); GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Magenta, DebugMsg); diff --git a/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp b/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp index f30e7ca..5ce7bd2 100644 --- a/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp +++ b/SwordNGun/Source/SwordNGun/Private/Components/SNGCharacterMovementComponent.cpp @@ -4,21 +4,21 @@ #include "Components/SNGCharacterMovementComponent.h" #include "Kismet/KismetMathLibrary.h" +#include "PhysicsEngine/PhysicsSettings.h" USNGCharacterMovementComponent::USNGCharacterMovementComponent() { // Defaults DefaultGroundFriction = 8.0f; - DefaultGravityScale = 1.0f; DefaultMaxWalkSpeed = 600.0f; DefaultRotationRate = FRotator(0.0f, 360.0f, 0.0f); // sprint - SprintingMaxWalkSpeed = 800.0f; - SprintLateralSpeedThreshold = 300.0f; + SprintingMaxWalkSpeed = 1000.0f; + SprintLateralSpeedThreshold = 500.0f; SprintingRotationRate = FRotator(0.0f, 180.0f, 0.0f); - TimeToInitiateSprint = 4.0f; - WalkToSprintInterpSpeed = 1.0f; + TimeToInitiateSprint = 2.0f; + WalkToSprintInterpSpeed = 4.0f; // firing FiringMaxWalkSpeed = 300.0f; @@ -26,11 +26,16 @@ USNGCharacterMovementComponent::USNGCharacterMovementComponent() // reloading ReloadingMaxWalkSpeed = 300.0f; - // Set defaults dealing with jumping and being airborne - DefaultJumpForce = 1000.0f; - DefaultAirFriction = 150.0f; - DefaultAirControl = 0.35; + // airborne defaults + DefaultAirControl = 0.3f; + // jump + MaxJumpHeight = 250.0f; + DesiredJumpDuration = 0.75f; + ComputerGravityScaleAndJumpZVelocity(); + + /* + // not used...yet MinJumpHeight = 200.0f; MaxJumpTime = 0.2f; @@ -38,6 +43,13 @@ USNGCharacterMovementComponent::USNGCharacterMovementComponent() MinAllowedDashHeight = 175.0f; MinAllowedAttackHeight = 175.0f; + */ + + // Character Movement component defaults + SetWalkableFloorAngle(45.622231f); + + AirControlBoostMultiplier = 0.0f; + AirControlBoostVelocityThreshold = 0.0f; } /** @@ -50,16 +62,48 @@ void USNGCharacterMovementComponent::RestoreMovementDefaults() GravityScale = DefaultGravityScale; RotationRate = DefaultRotationRate; MaxWalkSpeed = DefaultMaxWalkSpeed; - BrakingDecelerationFalling = DefaultAirFriction; AirControl = DefaultAirControl; - JumpZVelocity = DefaultJumpForce; + JumpZVelocity = DefaultJumpZVelocity; } +#if WITH_EDITOR +void USNGCharacterMovementComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) +{ + Super::PostEditChangeProperty(PropertyChangedEvent); + + const FProperty* PropertyThatChanged = PropertyChangedEvent.MemberProperty; + if (PropertyThatChanged && PropertyThatChanged->GetFName() == GET_MEMBER_NAME_CHECKED(USNGCharacterMovementComponent, MaxJumpHeight) || + PropertyThatChanged && PropertyThatChanged->GetFName() == GET_MEMBER_NAME_CHECKED(USNGCharacterMovementComponent, DesiredJumpDuration)) + { + // Compute WalkableFloorZ from the Angle. + ComputerGravityScaleAndJumpZVelocity(); + } +} + +void USNGCharacterMovementComponent::PostLoad() +{ + Super::PostLoad(); + + // Compute gravity scale and jump z velocity for first time + ComputerGravityScaleAndJumpZVelocity(); +} +#endif // WITH_EDITOR + void USNGCharacterMovementComponent::OnSprintTimer() { bIsSprinting = true; } +void USNGCharacterMovementComponent::ComputerGravityScaleAndJumpZVelocity() +{ + float HalfJumpDuration = DesiredJumpDuration / 2.0f; + DefaultJumpZVelocity = (2 * MaxJumpHeight) / HalfJumpDuration; + + float GameGravity = UPhysicsSettings::Get()->DefaultGravityZ; + float TargetGravity = (-2 * MaxJumpHeight) / (HalfJumpDuration * HalfJumpDuration); + DefaultGravityScale = TargetGravity / GameGravity; +} + void USNGCharacterMovementComponent::StartJump() { /* diff --git a/SwordNGun/Source/SwordNGun/Public/Components/SNGCharacterMovementComponent.h b/SwordNGun/Source/SwordNGun/Public/Components/SNGCharacterMovementComponent.h index 10f2985..44b272f 100644 --- a/SwordNGun/Source/SwordNGun/Public/Components/SNGCharacterMovementComponent.h +++ b/SwordNGun/Source/SwordNGun/Public/Components/SNGCharacterMovementComponent.h @@ -20,6 +20,8 @@ class SWORDNGUN_API USNGCharacterMovementComponent : public UCharacterMovementCo public: USNGCharacterMovementComponent(); + virtual void PostLoad() override; + /** * Instantly sets all movement parameters to their defaults values (i.e. ground friction to DefaultGroundFriction, * MaxWalkSpeed to DefaultMaxWalkSpeed, etc.) @@ -33,39 +35,45 @@ public: UFUNCTION(BlueprintCallable) FORCEINLINE bool GetIsSprinting() { return bIsSprinting; } +#if WITH_EDITOR + virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; +#endif // WITH_EDITOR + + + protected: // default ground /** Default friction when not performing any special actions and on the ground */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Ground.Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Ground|Defaults", meta=(ClampMin="0", UIMin="0")) float DefaultGroundFriction; /** Default ground walk speed when not performing any special actions */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Ground.Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Ground|Defaults", meta=(ClampMin="0", UIMin="0")) float DefaultMaxWalkSpeed; /** Default ground walk speed when not performing any special actions */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Ground.Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Ground|Defaults", meta=(ClampMin="0", UIMin="0")) FRotator DefaultRotationRate; // sprinting /** Ground walk speed when sprinting */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Ground.Sprint", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Ground|Sprint", meta=(ClampMin="0", UIMin="0")) float SprintingMaxWalkSpeed; /** Lateral speed the player needs to maintain to stay in the sprinting state */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Ground.Sprint", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Ground|Sprint", meta=(ClampMin="0", UIMin="0")) float SprintLateralSpeedThreshold; /** Default ground walk speed when not performing any special actions */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Ground.Sprint", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Ground|Sprint", meta=(ClampMin="0", UIMin="0")) FRotator SprintingRotationRate; /** How long after applying movement input should the character start sprinting? */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Ground.Sprint", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Ground|Sprint", meta=(ClampMin="0", UIMin="0")) float TimeToInitiateSprint; /** The speed in which the max walk speed to interpolated to the max sprint speed when a sprint has been initiated */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Ground.Sprint", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Ground|Sprint", meta=(ClampMin="0", UIMin="0")) float WalkToSprintInterpSpeed; FTimerHandle TimerHandle_SprintTimer; @@ -77,34 +85,53 @@ protected: // firing /** Ground walk speed when firing a ranged weapon */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Firing", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Firing", meta=(ClampMin="0", UIMin="0")) float FiringMaxWalkSpeed; // reloading /** Ground walk speed when reloading a ranged weapon */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Reloading", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Reloading", meta=(ClampMin="0", UIMin="0")) float ReloadingMaxWalkSpeed; // airborne /** Gravity scale when not performing any special actions */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Air.Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="SNG Character Movement|Air|Defaults", meta=(ClampMin="0", UIMin="0")) float DefaultGravityScale; - /** Force to continuously apply to character when they are holding the jump button */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Air.Defaults", meta=(ClampMin="0", UIMin="0")) - float DefaultJumpForce; + /** How much to dampen lateral velocities at the start of a jump */ + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Air|Defaults", meta=(ClampMin="0", UIMin="0")) + float LateralVelocityDampening; + /** + * How high (Z) is the character able to reach when holding the jump button for the maximum allowed time. + * + * This is used in conjunction with DesiredJumpDuration to derive DefaultGravityScale and JumpZVelocity. + */ + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Air|Jump", meta=(ClampMin="0", UIMin="0")) + float MaxJumpHeight; + + /** + * How long the character should be in the air for when performing a single jump and holding the jump button to reach + * the maximum jump height. + * + * This is used in conjunction with MaxJumpHeight to derive DefaultGravityScale and JumpZVelocity. + */ + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Air|Jump", meta=(ClampMin="0", UIMin="0")) + float DesiredJumpDuration; + + /** Force to continuously apply to character when they are holding the jump button */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="SNG Character Movement|Air|Jump", meta=(ClampMin="0", UIMin="0")) + float DefaultJumpZVelocity; + /** Minimum height a character must reach before jump force is no longer applied even if the jump input is not being held */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Air.Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Air|Jump", meta=(ClampMin="0", UIMin="0")) float MinJumpHeight; /** Max time the jump button can be held to give character upward velocity */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Air.Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Air|Jump", meta=(ClampMin="0", UIMin="0")) float MaxJumpTime; - /** How much to dampen lateral velocities at the start of a jump */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement.Air.Defaults", meta=(ClampMin="0", UIMin="0")) - float LateralVelocityDampening; + void ComputerGravityScaleAndJumpZVelocity(); /** * Sets up character velocities and jump parameters like the jump timer @@ -117,21 +144,17 @@ protected: */ UFUNCTION(BlueprintCallable) void AddJumpForce(); - - /** Default friction when not performing any special actions and in the air */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Character Movement: SNG Air Defaults", meta=(ClampMin="0", UIMin="0")) - float DefaultAirFriction; /** Default friction when not performing any special actions and in the air */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Character Movement: SNG Air Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Air|Defaults", meta=(ClampMin="0", UIMin="0")) float DefaultAirControl; /** Minimum distance from the ground a character has to be to be able to perform an air dash */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Character Movement: SNG Air Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Air|Defaults", meta=(ClampMin="0", UIMin="0")) float MinAllowedDashHeight; /** Minimum distance from the ground a character has to be to be able to perform an air attack */ - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Character Movement: SNG Air Defaults", meta=(ClampMin="0", UIMin="0")) + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="SNG Character Movement|Air|Defaults", meta=(ClampMin="0", UIMin="0")) float MinAllowedAttackHeight; virtual void BeginPlay() override;