diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 01be1e770..000000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -ko_fi: dyanikoglu diff --git a/ALSV4_CPP.uplugin b/ALSV4_CPP.uplugin index e7704bc9d..9beeaf9a7 100644 --- a/ALSV4_CPP.uplugin +++ b/ALSV4_CPP.uplugin @@ -1,16 +1,15 @@ { "FileVersion": 3, "Version": 1, - "VersionName": "4.19", + "VersionName": "4.26.0", "FriendlyName": "Advanced Locomotion System Community", "Description": "Performance optimized community version of LongmireLocomotion's Advanced Locomotion System V4", "Category": "Animation", "CreatedBy": "Doga Can Yanikoglu", "CreatedByURL": "https://github.com/dyanikoglu", "DocsURL": "https://github.com/dyanikoglu/ALS-Community", - "MarketplaceURL": "https://www.unrealengine.com/marketplace/en-US/product/advanced-locomotion-system-v1", "SupportURL": "https://github.com/dyanikoglu/ALS-Community/issues", - "EngineVersion": "4.26.0", + "EngineVersion": "5.4.0", "EnabledByDefault": true, "CanContainContent": true, "IsBetaVersion": false, @@ -29,10 +28,14 @@ ] } ], - "Plugins": [ - { - "Name": "Niagara", - "Enabled": true - } - ] + "Plugins": [ + { + "Name": "Niagara", + "Enabled": true + }, + { + "Name": "EnhancedInput", + "Enabled": true + } + ] } diff --git a/Config/DefaultInput.ini b/Config/DefaultInput.ini deleted file mode 100644 index eefd6be43..000000000 --- a/Config/DefaultInput.ini +++ /dev/null @@ -1,37 +0,0 @@ -[/Script/Engine.InputSettings] -+ActionMappings=(ActionName="JumpAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=SpaceBar) -+ActionMappings=(ActionName="JumpAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Bottom) -+ActionMappings=(ActionName="StanceAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftAlt) -+ActionMappings=(ActionName="SprintAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftShift) -+ActionMappings=(ActionName="StanceAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Right) -+ActionMappings=(ActionName="SprintAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_LeftThumbstick) -+ActionMappings=(ActionName="WalkAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=LeftControl) -+ActionMappings=(ActionName="WalkAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_RightShoulder) -+ActionMappings=(ActionName="AimAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=RightMouseButton) -+ActionMappings=(ActionName="AimAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_LeftTrigger) -+ActionMappings=(ActionName="SelectRotationMode_1",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=One) -+ActionMappings=(ActionName="SelectRotationMode_2",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Two) -+ActionMappings=(ActionName="SelectRotationMode_1",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_DPad_Left) -+ActionMappings=(ActionName="SelectRotationMode_2",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_DPad_Right) -+ActionMappings=(ActionName="CameraAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=C) -+ActionMappings=(ActionName="CameraAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_RightThumbstick) -+ActionMappings=(ActionName="RagdollAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=X) -+ActionMappings=(ActionName="RagdollAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_Special_Left) -+ActionMappings=(ActionName="CycleOverlayUp",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=MouseScrollUp) -+ActionMappings=(ActionName="CycleOverlayDown",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=MouseScrollDown) -+ActionMappings=(ActionName="CycleOverlayUp",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_DPad_Up) -+ActionMappings=(ActionName="CycleOverlayDown",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_DPad_Down) -+ActionMappings=(ActionName="OpenOverlayMenu",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Q) -+ActionMappings=(ActionName="OpenOverlayMenu",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_LeftShoulder) -+ActionMappings=(ActionName="UseAction",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=E) -+AxisMappings=(AxisName="MoveForward/Backwards",Scale=1.000000,Key=W) -+AxisMappings=(AxisName="MoveRight/Left",Scale=1.000000,Key=D) -+AxisMappings=(AxisName="LookUp/Down",Scale=-1.000000,Key=MouseY) -+AxisMappings=(AxisName="LookLeft/Right",Scale=1.000000,Key=MouseX) -+AxisMappings=(AxisName="MoveForward/Backwards",Scale=-1.000000,Key=S) -+AxisMappings=(AxisName="MoveRight/Left",Scale=-1.000000,Key=A) -+AxisMappings=(AxisName="MoveForward/Backwards",Scale=1.000000,Key=Gamepad_LeftY) -+AxisMappings=(AxisName="MoveRight/Left",Scale=1.000000,Key=Gamepad_LeftX) -+AxisMappings=(AxisName="LookUp/Down",Scale=1.000000,Key=Gamepad_RightY) -+AxisMappings=(AxisName="LookLeft/Right",Scale=1.000000,Key=Gamepad_RightX) - diff --git a/Content/AdvancedLocomotionV4/Audio/Background/Starter_Birds01.uasset b/Content/AdvancedLocomotionV4/Audio/Background/Starter_Birds01.uasset index e3988ddf1..b0b79effa 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Background/Starter_Birds01.uasset and b/Content/AdvancedLocomotionV4/Audio/Background/Starter_Birds01.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Background/Starter_Wind05.uasset b/Content/AdvancedLocomotionV4/Audio/Background/Starter_Wind05.uasset index fe3b14cf6..268aa6566 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Background/Starter_Wind05.uasset and b/Content/AdvancedLocomotionV4/Audio/Background/Starter_Wind05.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Background/Starter_Wind06.uasset b/Content/AdvancedLocomotionV4/Audio/Background/Starter_Wind06.uasset index 6248fa16e..c969ca68f 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Background/Starter_Wind06.uasset and b/Content/AdvancedLocomotionV4/Audio/Background/Starter_Wind06.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_01.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_01.uasset index 18212bd03..55b88244a 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_01.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_01.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_02.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_02.uasset index ed0e033ed..d664d714c 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_02.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_02.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_03.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_03.uasset index 1f353f4d7..c3f6c8773 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_03.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_03.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_04.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_04.uasset index 1911ae195..a2f89f5cd 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_04.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Pivot_04.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_01.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_01.uasset index 20f8dcc89..0880fa308 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_01.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_01.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_02.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_02.uasset index 84dc2b075..cb0f49482 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_02.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_02.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_03.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_03.uasset index 94aed9e4c..c1c1a9fdc 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_03.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_03.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_04.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_04.uasset index 62fc72072..0b3f6253f 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_04.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Run_04.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_01.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_01.uasset index 869c4ec57..b73404f22 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_01.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_01.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_02.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_02.uasset index ab3a84925..8cfd1af5b 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_02.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_02.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_03.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_03.uasset index 1bb5a90df..41ab81519 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_03.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Step_03.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_01.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_01.uasset index b04fd5680..f1fa24ebc 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_01.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_01.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_02.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_02.uasset index 87210e4c9..815b4aa98 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_02.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_02.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_03.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_03.uasset index 42ed71241..a2bcd7f73 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_03.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_03.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_04.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_04.uasset index a24c74a18..0c181b990 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_04.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_04.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_05.uasset b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_05.uasset index 6085f5038..04ff95703 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_05.uasset and b/Content/AdvancedLocomotionV4/Audio/Footsteps/Concrete_Walk_05.uasset differ diff --git a/Content/AdvancedLocomotionV4/Audio/UI/Click.uasset b/Content/AdvancedLocomotionV4/Audio/UI/Click.uasset index 090d934dd..c5c20990c 100644 Binary files a/Content/AdvancedLocomotionV4/Audio/UI/Click.uasset and b/Content/AdvancedLocomotionV4/Audio/UI/Click.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/AnimModifiers/Calculate_RotationAmount.uasset b/Content/AdvancedLocomotionV4/Blueprints/AnimModifiers/Calculate_RotationAmount.uasset index 089346c5a..8a2d92560 100644 Binary files a/Content/AdvancedLocomotionV4/Blueprints/AnimModifiers/Calculate_RotationAmount.uasset and b/Content/AdvancedLocomotionV4/Blueprints/AnimModifiers/Calculate_RotationAmount.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/CameraSystem/ALS_PlayerCameraManager.uasset b/Content/AdvancedLocomotionV4/Blueprints/CameraSystem/ALS_PlayerCameraManager.uasset index 78ea95403..4d97bc669 100644 Binary files a/Content/AdvancedLocomotionV4/Blueprints/CameraSystem/ALS_PlayerCameraManager.uasset and b/Content/AdvancedLocomotionV4/Blueprints/CameraSystem/ALS_PlayerCameraManager.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/AI/ALS_AIBP.uasset b/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/AI/ALS_AIBP.uasset index a825c35f2..587ee4d9e 100644 Binary files a/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/AI/ALS_AIBP.uasset and b/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/AI/ALS_AIBP.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/ALS_CharacterBP.uasset b/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/ALS_CharacterBP.uasset index cdfb70f44..05fb5d0a2 100644 Binary files a/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/ALS_CharacterBP.uasset and b/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/ALS_CharacterBP.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/ALS_Player_Controller.uasset b/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/ALS_Player_Controller.uasset index 191f523ed..e8f4f0da3 100644 Binary files a/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/ALS_Player_Controller.uasset and b/Content/AdvancedLocomotionV4/Blueprints/CharacterLogic/ALS_Player_Controller.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Components/DebugComponent.uasset b/Content/AdvancedLocomotionV4/Blueprints/Components/DebugComponent.uasset index b8e3606d4..c2dc9be3a 100644 Binary files a/Content/AdvancedLocomotionV4/Blueprints/Components/DebugComponent.uasset and b/Content/AdvancedLocomotionV4/Blueprints/Components/DebugComponent.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugFocusedCharacterCycleAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugFocusedCharacterCycleAction.uasset new file mode 100644 index 000000000..6839deb23 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugFocusedCharacterCycleAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugOpenOverlayMenuAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugOpenOverlayMenuAction.uasset new file mode 100644 index 000000000..de0cf7095 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugOpenOverlayMenuAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugOverlayMenuCycleAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugOverlayMenuCycleAction.uasset new file mode 100644 index 000000000..12b333da3 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugOverlayMenuCycleAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleCharacterInfoAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleCharacterInfoAction.uasset new file mode 100644 index 000000000..6d3de21f3 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleCharacterInfoAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleDebugMeshAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleDebugMeshAction.uasset new file mode 100644 index 000000000..3093b6ab0 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleDebugMeshAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleDebugViewAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleDebugViewAction.uasset new file mode 100644 index 000000000..d68cd2089 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleDebugViewAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleHudAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleHudAction.uasset new file mode 100644 index 000000000..6c98c5800 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleHudAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleLayerColorsAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleLayerColorsAction.uasset new file mode 100644 index 000000000..fa93946d6 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleLayerColorsAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleShapesAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleShapesAction.uasset new file mode 100644 index 000000000..4f691789a Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleShapesAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleSlomoAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleSlomoAction.uasset new file mode 100644 index 000000000..3c60407a2 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleSlomoAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleTracesAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleTracesAction.uasset new file mode 100644 index 000000000..ffae55a5b Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Debug/DebugToggleTracesAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/AimAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/AimAction.uasset new file mode 100644 index 000000000..8af43bb17 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/AimAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraHeldAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraHeldAction.uasset new file mode 100644 index 000000000..496aeb2fb Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraHeldAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraRightAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraRightAction.uasset new file mode 100644 index 000000000..2d5dc4d3a Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraRightAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraTapAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraTapAction.uasset new file mode 100644 index 000000000..451736570 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraTapAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraUpAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraUpAction.uasset new file mode 100644 index 000000000..78edb9d4a Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/CameraUpAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/ForwardMovementAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/ForwardMovementAction.uasset new file mode 100644 index 000000000..d06f1f422 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/ForwardMovementAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/JumpAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/JumpAction.uasset new file mode 100644 index 000000000..4d82c4079 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/JumpAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/LookingDirectionAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/LookingDirectionAction.uasset new file mode 100644 index 000000000..e0e834084 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/LookingDirectionAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/RagdollAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/RagdollAction.uasset new file mode 100644 index 000000000..44ac9860e Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/RagdollAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/RightMovementAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/RightMovementAction.uasset new file mode 100644 index 000000000..4da92aef7 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/RightMovementAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/SprintAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/SprintAction.uasset new file mode 100644 index 000000000..69a3e5d12 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/SprintAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/StanceAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/StanceAction.uasset new file mode 100644 index 000000000..e4dba4332 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/StanceAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/VelocityDirectionAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/VelocityDirectionAction.uasset new file mode 100644 index 000000000..f38133fa0 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/VelocityDirectionAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/Default/WalkAction.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/WalkAction.uasset new file mode 100644 index 000000000..b9505168a Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/Default/WalkAction.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/IMC_Debug.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/IMC_Debug.uasset new file mode 100644 index 000000000..bf447f341 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/IMC_Debug.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/Input/IMC_Default.uasset b/Content/AdvancedLocomotionV4/Blueprints/Input/IMC_Default.uasset new file mode 100644 index 000000000..862be8025 Binary files /dev/null and b/Content/AdvancedLocomotionV4/Blueprints/Input/IMC_Default.uasset differ diff --git a/Content/AdvancedLocomotionV4/Blueprints/UI/ALS_HUD.uasset b/Content/AdvancedLocomotionV4/Blueprints/UI/ALS_HUD.uasset index ca70f7b5e..84547535a 100644 Binary files a/Content/AdvancedLocomotionV4/Blueprints/UI/ALS_HUD.uasset and b/Content/AdvancedLocomotionV4/Blueprints/UI/ALS_HUD.uasset differ diff --git a/Content/AdvancedLocomotionV4/CharacterAssets/MannequinSkeleton/ALS_AnimBP.uasset b/Content/AdvancedLocomotionV4/CharacterAssets/MannequinSkeleton/ALS_AnimBP.uasset index d4436685d..b83c98924 100644 Binary files a/Content/AdvancedLocomotionV4/CharacterAssets/MannequinSkeleton/ALS_AnimBP.uasset and b/Content/AdvancedLocomotionV4/CharacterAssets/MannequinSkeleton/ALS_AnimBP.uasset differ diff --git a/Content/AdvancedLocomotionV4/Levels/ALS_DemoLevel.umap b/Content/AdvancedLocomotionV4/Levels/ALS_DemoLevel.umap index ff7628ed2..b168d7ca2 100644 Binary files a/Content/AdvancedLocomotionV4/Levels/ALS_DemoLevel.umap and b/Content/AdvancedLocomotionV4/Levels/ALS_DemoLevel.umap differ diff --git a/README.md b/README.md index b44d0848f..0c198dd75 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,38 @@ -# Advanced Locomotion System Community +# Advanced Locomotion System - Community Version ![image](https://github.com/dyanikoglu/ALS-Community/raw/main/Resources/Readme_Content_2.gif) -Replicated and optimized community version of [Advanced Locomotion System V4](https://www.unrealengine.com/marketplace/en-US/product/advanced-locomotion-system-v1) for **Unreal Engine 4.26** with additional bug fixes. +Replicated and optimized version of [Advanced Locomotion System V4](https://www.unrealengine.com/marketplace/en-US/product/advanced-locomotion-system-v1) for **Unreal Engine 5.4** with additional bug fixes + +

+ +

+ +## About This Repository + +Advanced Locomotion system is built upon pretty outdated animation programming techniques of pre Unreal Engine 5 era, and I highly recommended to utilize other available locomotion systems, such as Epic's Lyra sample project. This repository will only receive engine compatibility fixes from now. ## Supported Platforms - Windows - Linux -*Mac, Android, IOS, and console builds are not tested and supported at the moment. Use the plugin on those platforms with your own risk.* +*Console, Mac and mobile platforms are not tested and supported at the moment. Use the plugin on those platforms with your own risk.* ## Features -- Based on latest marketplace release (V4) of Advanced Locomotion System -- Fully implemented in C++ -- Full replication support with low bandwidth usage -- Plugin structure -- Highly optimized for production -- Mantling and debugging features are implemented as a separate plug-in/plug-out type actor component to reduce total overhead on base character class -- Improved footstep behavior with Niagara particle & decal support. -- Lots of bug fixes additional to marketplace version +- Fully implemented and optimized in C++. Implementation is based on latest marketplace release (V4) of ALS +- Complete replication support with low bandwidth usage (Ragdoll replication is in experimental state) +- Redesigned as plugin +- Animation blueprint is optimized with new property binding feature +- Player input is handled with new Enhanced Input Plugin +- Mantling and debugging features are implemented as separate actor components to reduce total overhead on base character class +- Improved footstep system with decal & Niagara particle support +- Lots of additional bug fixes ## Known Issues & Discussion - See [Issues](https://github.com/dyanikoglu/ALS-Community/issues) section for list of known issues -- See [Discussions](https://github.com/dyanikoglu/ALS-Community/discussions) section to discuss anything about the plugin, and ask questions. Please do not open an issue to ask questions about the plugin. - -## Setting Up The Plugin -- **C++ project is a requirement. BP projects are currently not supported.** -- Clone the repository inside your project's `Plugins` folder, or download the latest release and extract it into your project's `Plugins` folder. -- Put `Config/DefaultInput.ini` from the plugin folder inside your project's config folder. If your project already have this .ini file, merge it into yours. -- Regenerate visual studio project files and build your project. -- Launch the project, and enable plugin content viewer as seen below. This will show contents of the plugin in your content browser: -![image](https://github.com/dyanikoglu/ALS-Community/raw/main/Resources/Readme_Content_1.png) +- See [Discussions](https://github.com/dyanikoglu/ALS-Community/discussions) section to discuss anything about the plugin, and ask questions. Please do not open an issue for questions. + +## Documentation +Instructions for setting up the plugin can be found on [Wiki](https://github.com/dyanikoglu/ALS-Community/wiki/Setting-Up-The-Plugin) section. ## License & Contribution **Source code** of the plugin is licensed under MIT license, and other developers are encouraged to fork the repository, open issues & pull requests to help the development. diff --git a/Resources/Readme_Content_1.png b/Resources/Readme_Content_1.png deleted file mode 100644 index e5cc9b5c7..000000000 Binary files a/Resources/Readme_Content_1.png and /dev/null differ diff --git a/Resources/Readme_Content_3.png b/Resources/Readme_Content_3.png new file mode 100644 index 000000000..7dae384c5 Binary files /dev/null and b/Resources/Readme_Content_3.png differ diff --git a/Resources/Readme_Content_4.png b/Resources/Readme_Content_4.png new file mode 100644 index 000000000..25816e3b2 Binary files /dev/null and b/Resources/Readme_Content_4.png differ diff --git a/Source/ALSV4_CPP/ALSV4_CPP.Build.cs b/Source/ALSV4_CPP/ALSV4_CPP.Build.cs index 1afa59371..90a5d8203 100644 --- a/Source/ALSV4_CPP/ALSV4_CPP.Build.cs +++ b/Source/ALSV4_CPP/ALSV4_CPP.Build.cs @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community using UnrealBuildTool; @@ -14,7 +10,8 @@ public ALSV4_CPP(ReadOnlyTargetRules Target) : base(Target) PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PublicDependencyModuleNames.AddRange(new[] - {"Core", "CoreUObject", "Engine", "InputCore", "NavigationSystem", "AIModule", "GameplayTasks","PhysicsCore", "Niagara"}); + {"Core", "CoreUObject", "Engine", "InputCore", "NavigationSystem", "AIModule", "GameplayTasks","PhysicsCore", "Niagara", "EnhancedInput" + }); PrivateDependencyModuleNames.AddRange(new[] {"Slate", "SlateCore"}); } diff --git a/Source/ALSV4_CPP/ALSV4_CPP.cpp b/Source/ALSV4_CPP/ALSV4_CPP.cpp index a2a7df1db..13f08144a 100644 --- a/Source/ALSV4_CPP/ALSV4_CPP.cpp +++ b/Source/ALSV4_CPP/ALSV4_CPP.cpp @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "ALSV4_CPP.h" #include "Modules/ModuleManager.h" diff --git a/Source/ALSV4_CPP/ALSV4_CPP.h b/Source/ALSV4_CPP/ALSV4_CPP.h index 09e8b49bb..d3c532935 100644 --- a/Source/ALSV4_CPP/ALSV4_CPP.h +++ b/Source/ALSV4_CPP/ALSV4_CPP.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once diff --git a/Source/ALSV4_CPP/Private/AI/ALSAIController.cpp b/Source/ALSV4_CPP/Private/AI/ALSAIController.cpp index 1c416b8a6..257412fb5 100644 --- a/Source/ALSV4_CPP/Private/AI/ALSAIController.cpp +++ b/Source/ALSV4_CPP/Private/AI/ALSAIController.cpp @@ -1,12 +1,10 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Jens Bjarne Myhre -// Contributors: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "AI/ALSAIController.h" +#include "Character/ALSBaseCharacter.h" + AALSAIController::AALSAIController() { } @@ -20,3 +18,18 @@ void AALSAIController::OnPossess(APawn* InPawn) RunBehaviorTree(Behaviour); } } + +FVector AALSAIController::GetFocalPointOnActor(const AActor* Actor) const +{ + if (Actor == nullptr) + { + return FAISystem::InvalidLocation; + } + const APawn* FocusPawn = Cast(Actor); + if (FocusPawn) + { + // Focus on pawn's eye view point + return FocusPawn->GetPawnViewLocation(); + } + return Actor->GetActorLocation(); +} diff --git a/Source/ALSV4_CPP/Private/AI/ALS_BTTask_GetRandomLocation.cpp b/Source/ALSV4_CPP/Private/AI/ALS_BTTask_GetRandomLocation.cpp index f24f333e8..7f103bb1a 100644 --- a/Source/ALSV4_CPP/Private/AI/ALS_BTTask_GetRandomLocation.cpp +++ b/Source/ALSV4_CPP/Private/AI/ALS_BTTask_GetRandomLocation.cpp @@ -1,12 +1,9 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Jens Bjarne Myhre -// Contributors: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "AI/ALS_BTTask_GetRandomLocation.h" #include "AIController.h" +#include "NavFilters/NavigationQueryFilter.h" #include "BehaviorTree/BlackboardComponent.h" #include "BehaviorTree/Blackboard/BlackboardKeyType_Vector.h" diff --git a/Source/ALSV4_CPP/Private/AI/ALS_BTTask_SetFocusToPlayer.cpp b/Source/ALSV4_CPP/Private/AI/ALS_BTTask_SetFocusToPlayer.cpp index 1c97c403d..cc7a7e1a5 100644 --- a/Source/ALSV4_CPP/Private/AI/ALS_BTTask_SetFocusToPlayer.cpp +++ b/Source/ALSV4_CPP/Private/AI/ALS_BTTask_SetFocusToPlayer.cpp @@ -1,11 +1,8 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Jens Bjarne Myhre -// Contributors: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "AI/ALS_BTTask_SetFocusToPlayer.h" +#include "Engine/World.h" #include "Runtime/Engine/Classes/Kismet/GameplayStatics.h" #include "AIController.h" diff --git a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp index abd9c21df..899f7fdc5 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSBaseCharacter.cpp @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: Haziq Fadhil, Drakynfly, CanisHelix +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/ALSBaseCharacter.h" @@ -12,9 +8,9 @@ #include "Character/Animation/ALSCharacterAnimInstance.h" #include "Character/Animation/ALSPlayerCameraBehavior.h" #include "Library/ALSMathLibrary.h" +#include "Components/ALSDebugComponent.h" + #include "Components/CapsuleComponent.h" -#include "Components/TimelineComponent.h" -#include "Curves/CurveVector.h" #include "Curves/CurveFloat.h" #include "Character/ALSCharacterMovementComponent.h" #include "GameFramework/CharacterMovementComponent.h" @@ -23,6 +19,17 @@ #include "TimerManager.h" #include "Net/UnrealNetwork.h" + +const FName NAME_FP_Camera(TEXT("FP_Camera")); +const FName NAME_Pelvis(TEXT("Pelvis")); +const FName NAME_RagdollPose(TEXT("RagdollPose")); +const FName NAME_RotationAmount(TEXT("RotationAmount")); +const FName NAME_YawOffset(TEXT("YawOffset")); +const FName NAME_pelvis(TEXT("pelvis")); +const FName NAME_root(TEXT("root")); +const FName NAME_spine_03(TEXT("spine_03")); + + AALSBaseCharacter::AALSBaseCharacter(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer.SetDefaultSubobjectClass(CharacterMovementComponentName)) { @@ -32,31 +39,6 @@ AALSBaseCharacter::AALSBaseCharacter(const FObjectInitializer& ObjectInitializer SetReplicatingMovement(true); } -void AALSBaseCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) -{ - Super::SetupPlayerInputComponent(PlayerInputComponent); - - PlayerInputComponent->BindAxis("MoveForward/Backwards", this, &AALSBaseCharacter::PlayerForwardMovementInput); - PlayerInputComponent->BindAxis("MoveRight/Left", this, &AALSBaseCharacter::PlayerRightMovementInput); - PlayerInputComponent->BindAxis("LookUp/Down", this, &AALSBaseCharacter::PlayerCameraUpInput); - PlayerInputComponent->BindAxis("LookLeft/Right", this, &AALSBaseCharacter::PlayerCameraRightInput); - PlayerInputComponent->BindAction("JumpAction", IE_Pressed, this, &AALSBaseCharacter::JumpPressedAction); - PlayerInputComponent->BindAction("JumpAction", IE_Released, this, &AALSBaseCharacter::JumpReleasedAction); - PlayerInputComponent->BindAction("StanceAction", IE_Pressed, this, &AALSBaseCharacter::StancePressedAction); - PlayerInputComponent->BindAction("WalkAction", IE_Pressed, this, &AALSBaseCharacter::WalkPressedAction); - PlayerInputComponent->BindAction("RagdollAction", IE_Pressed, this, &AALSBaseCharacter::RagdollPressedAction); - PlayerInputComponent->BindAction("SelectRotationMode_1", IE_Pressed, this, - &AALSBaseCharacter::VelocityDirectionPressedAction); - PlayerInputComponent->BindAction("SelectRotationMode_2", IE_Pressed, this, - &AALSBaseCharacter::LookingDirectionPressedAction); - PlayerInputComponent->BindAction("SprintAction", IE_Pressed, this, &AALSBaseCharacter::SprintPressedAction); - PlayerInputComponent->BindAction("SprintAction", IE_Released, this, &AALSBaseCharacter::SprintReleasedAction); - PlayerInputComponent->BindAction("AimAction", IE_Pressed, this, &AALSBaseCharacter::AimPressedAction); - PlayerInputComponent->BindAction("AimAction", IE_Released, this, &AALSBaseCharacter::AimReleasedAction); - PlayerInputComponent->BindAction("CameraAction", IE_Pressed, this, &AALSBaseCharacter::CameraPressedAction); - PlayerInputComponent->BindAction("CameraAction", IE_Released, this, &AALSBaseCharacter::CameraReleasedAction); -} - void AALSBaseCharacter::PostInitializeComponents() { Super::PostInitializeComponents(); @@ -89,7 +71,11 @@ void AALSBaseCharacter::OnBreakfall_Implementation() void AALSBaseCharacter::Replicated_PlayMontage_Implementation(UAnimMontage* Montage, float PlayRate) { // Roll: Simply play a Root Motion Montage. - MainAnimInstance->Montage_Play(Montage, PlayRate); + if (GetMesh()->GetAnimInstance()) + { + GetMesh()->GetAnimInstance()->Montage_Play(Montage, PlayRate); + } + Server_PlayMontage(Montage, PlayRate); } @@ -106,22 +92,8 @@ void AALSBaseCharacter::BeginPlay() // Set the Movement Model SetMovementModel(); - // Once, force set variables in anim bp. This ensures anim instance & character starts synchronized - FALSAnimCharacterInformation& AnimData = MainAnimInstance->GetCharacterInformationMutable(); - MainAnimInstance->Gait = DesiredGait; - MainAnimInstance->Stance = DesiredStance; - MainAnimInstance->RotationMode = DesiredRotationMode; - AnimData.ViewMode = ViewMode; - MainAnimInstance->OverlayState = OverlayState; - AnimData.PrevMovementState = PrevMovementState; - MainAnimInstance->MovementState = MovementState; - - // Update states to use the initial desired values. - SetGait(DesiredGait); - SetStance(DesiredStance); - SetRotationMode(DesiredRotationMode); - SetViewMode(ViewMode); - SetOverlayState(OverlayState); + // Force update states to use the initial desired values. + ForceUpdateCharacterState(); if (Stance == EALSStance::Standing) { @@ -137,30 +109,14 @@ void AALSBaseCharacter::BeginPlay() LastVelocityRotation = TargetRotation; LastMovementInputRotation = TargetRotation; - if (GetLocalRole() == ROLE_SimulatedProxy) + if (GetMesh()->GetAnimInstance() && GetLocalRole() == ROLE_SimulatedProxy) { - MainAnimInstance->SetRootMotionMode(ERootMotionMode::IgnoreRootMotion); + GetMesh()->GetAnimInstance()->SetRootMotionMode(ERootMotionMode::IgnoreRootMotion); } -} -void AALSBaseCharacter::PreInitializeComponents() -{ - Super::PreInitializeComponents(); - - MainAnimInstance = Cast(GetMesh()->GetAnimInstance()); - if (!MainAnimInstance) - { - // Animation instance should be assigned if we're not in editor preview - checkf(GetWorld()->WorldType == EWorldType::EditorPreview, - TEXT("%s doesn't have a valid animation instance assigned. That's not allowed"), - *GetName()); - } -} + MyCharacterMovementComponent->SetMovementSettings(GetTargetMovementSettings()); -void AALSBaseCharacter::SetAimYawRate(float NewAimYawRate) -{ - AimYawRate = NewAimYawRate; - MainAnimInstance->GetCharacterInformationMutable().AimYawRate = AimYawRate; + ALSDebugComponent = FindComponentByClass(); } void AALSBaseCharacter::Tick(float DeltaTime) @@ -205,9 +161,13 @@ void AALSBaseCharacter::RagdollStart() DefVisBasedTickOp = GetMesh()->VisibilityBasedAnimTickOption; GetMesh()->VisibilityBasedAnimTickOption = EVisibilityBasedAnimTickOption::AlwaysTickPoseAndRefreshBones; } - TargetRagdollLocation = GetMesh()->GetSocketLocation(FName(TEXT("Pelvis"))); + TargetRagdollLocation = GetMesh()->GetSocketLocation(NAME_Pelvis); ServerRagdollPull = 0; + // Disable URO + bPreRagdollURO = GetMesh()->bEnableUpdateRateOptimizations; + GetMesh()->bEnableUpdateRateOptimizations = false; + // Step 1: Clear the Character Movement Mode and set the Movement State to Ragdoll GetCharacterMovement()->SetMovementMode(MOVE_None); SetMovementState(EALSMovementState::Ragdoll); @@ -216,10 +176,16 @@ void AALSBaseCharacter::RagdollStart() GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); GetMesh()->SetCollisionObjectType(ECC_PhysicsBody); GetMesh()->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); - GetMesh()->SetAllBodiesBelowSimulatePhysics(FName(TEXT("Pelvis")), true, true); + GetMesh()->SetAllBodiesBelowSimulatePhysics(NAME_Pelvis, true, true); // Step 3: Stop any active montages. - MainAnimInstance->Montage_Stop(0.2f); + if (GetMesh()->GetAnimInstance()) + { + GetMesh()->GetAnimInstance()->Montage_Stop(0.2f); + } + + // Fixes character mesh is showing default A pose for a split-second just before ragdoll ends in listen server games + GetMesh()->bOnlyAllowAutonomousTickPose = true; SetReplicateMovement(false); } @@ -234,24 +200,28 @@ void AALSBaseCharacter::RagdollEnd() GetMesh()->VisibilityBasedAnimTickOption = DefVisBasedTickOp; } + GetMesh()->bEnableUpdateRateOptimizations = bPreRagdollURO; + + // Revert back to default settings MyCharacterMovementComponent->bIgnoreClientMovementErrorChecksAndCorrection = 0; + GetMesh()->bOnlyAllowAutonomousTickPose = false; SetReplicateMovement(true); - if (!MainAnimInstance) + // Step 1: Save a snapshot of the current Ragdoll Pose for use in AnimGraph to blend out of the ragdoll + if (GetMesh()->GetAnimInstance()) { - return; + GetMesh()->GetAnimInstance()->SavePoseSnapshot(NAME_RagdollPose); } - // Step 1: Save a snapshot of the current Ragdoll Pose for use in AnimGraph to blend out of the ragdoll - MainAnimInstance->SavePoseSnapshot(FName(TEXT("RagdollPose"))); - // Step 2: If the ragdoll is on the ground, set the movement mode to walking and play a Get Up animation. // If not, set the movement mode to falling and update the character movement velocity to match the last ragdoll velocity. if (bRagdollOnGround) { GetCharacterMovement()->SetMovementMode(MOVE_Walking); - MainAnimInstance->Montage_Play(GetGetUpAnimation(bRagdollFaceUp), - 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); + if (GetMesh()->GetAnimInstance()) + { + GetMesh()->GetAnimInstance()->Montage_Play(GetGetUpAnimation(bRagdollFaceUp), 1.0f, EMontagePlayReturnType::MontageLength, 0.0f, true); + } } else { @@ -276,33 +246,29 @@ void AALSBaseCharacter::Server_SetMeshLocationDuringRagdoll_Implementation(FVect TargetRagdollLocation = MeshLocation; } -void AALSBaseCharacter::SetMovementState(const EALSMovementState NewState) +void AALSBaseCharacter::SetMovementState(const EALSMovementState NewState, bool bForce) { - if (MovementState != NewState) + if (bForce || MovementState != NewState) { PrevMovementState = MovementState; MovementState = NewState; - FALSAnimCharacterInformation& AnimData = MainAnimInstance->GetCharacterInformationMutable(); - AnimData.PrevMovementState = PrevMovementState; - MainAnimInstance->MovementState = MovementState; OnMovementStateChanged(PrevMovementState); } } -void AALSBaseCharacter::SetMovementAction(const EALSMovementAction NewAction) +void AALSBaseCharacter::SetMovementAction(const EALSMovementAction NewAction, bool bForce) { - if (MovementAction != NewAction) + if (bForce || MovementAction != NewAction) { const EALSMovementAction Prev = MovementAction; MovementAction = NewAction; - MainAnimInstance->MovementAction = MovementAction; OnMovementActionChanged(Prev); } } -void AALSBaseCharacter::SetStance(const EALSStance NewStance) +void AALSBaseCharacter::SetStance(const EALSStance NewStance, bool bForce) { - if (Stance != NewStance) + if (bForce || Stance != NewStance) { const EALSStance Prev = Stance; Stance = NewStance; @@ -310,9 +276,14 @@ void AALSBaseCharacter::SetStance(const EALSStance NewStance) } } -void AALSBaseCharacter::SetGait(const EALSGait NewGait) +void AALSBaseCharacter::SetOverlayOverrideState(int32 NewState) { - if (Gait != NewGait) + OverlayOverrideState = NewState; +} + +void AALSBaseCharacter::SetGait(const EALSGait NewGait, bool bForce) +{ + if (bForce || Gait != NewGait) { const EALSGait Prev = Gait; Gait = NewGait; @@ -363,9 +334,9 @@ void AALSBaseCharacter::Server_SetDesiredRotationMode_Implementation(EALSRotatio SetDesiredRotationMode(NewRotMode); } -void AALSBaseCharacter::SetRotationMode(const EALSRotationMode NewRotationMode) +void AALSBaseCharacter::SetRotationMode(const EALSRotationMode NewRotationMode, bool bForce) { - if (RotationMode != NewRotationMode) + if (bForce || RotationMode != NewRotationMode) { const EALSRotationMode Prev = RotationMode; RotationMode = NewRotationMode; @@ -373,20 +344,20 @@ void AALSBaseCharacter::SetRotationMode(const EALSRotationMode NewRotationMode) if (GetLocalRole() == ROLE_AutonomousProxy) { - Server_SetRotationMode(NewRotationMode); + Server_SetRotationMode(NewRotationMode, bForce); } } } -void AALSBaseCharacter::Server_SetRotationMode_Implementation(EALSRotationMode NewRotationMode) +void AALSBaseCharacter::Server_SetRotationMode_Implementation(EALSRotationMode NewRotationMode, bool bForce) { - SetRotationMode(NewRotationMode); + SetRotationMode(NewRotationMode, bForce); } -void AALSBaseCharacter::SetViewMode(const EALSViewMode NewViewMode) +void AALSBaseCharacter::SetViewMode(const EALSViewMode NewViewMode, bool bForce) { - if (ViewMode != NewViewMode) + if (bForce || ViewMode != NewViewMode) { const EALSViewMode Prev = ViewMode; ViewMode = NewViewMode; @@ -394,19 +365,19 @@ void AALSBaseCharacter::SetViewMode(const EALSViewMode NewViewMode) if (GetLocalRole() == ROLE_AutonomousProxy) { - Server_SetViewMode(NewViewMode); + Server_SetViewMode(NewViewMode, bForce); } } } -void AALSBaseCharacter::Server_SetViewMode_Implementation(EALSViewMode NewViewMode) +void AALSBaseCharacter::Server_SetViewMode_Implementation(EALSViewMode NewViewMode, bool bForce) { - SetViewMode(NewViewMode); + SetViewMode(NewViewMode, bForce); } -void AALSBaseCharacter::SetOverlayState(const EALSOverlayState NewState) +void AALSBaseCharacter::SetOverlayState(const EALSOverlayState NewState, bool bForce) { - if (OverlayState != NewState) + if (bForce || OverlayState != NewState) { const EALSOverlayState Prev = OverlayState; OverlayState = NewState; @@ -414,15 +385,20 @@ void AALSBaseCharacter::SetOverlayState(const EALSOverlayState NewState) if (GetLocalRole() == ROLE_AutonomousProxy) { - Server_SetOverlayState(NewState); + Server_SetOverlayState(NewState, bForce); } } } +void AALSBaseCharacter::SetGroundedEntryState(EALSGroundedEntryState NewState) +{ + GroundedEntryState = NewState; +} + -void AALSBaseCharacter::Server_SetOverlayState_Implementation(EALSOverlayState NewState) +void AALSBaseCharacter::Server_SetOverlayState_Implementation(EALSOverlayState NewState, bool bForce) { - SetOverlayState(NewState); + SetOverlayState(NewState, bForce); } void AALSBaseCharacter::EventOnLanded() @@ -459,21 +435,26 @@ void AALSBaseCharacter::EventOnJumped() { // Set the new In Air Rotation to the velocity rotation if speed is greater than 100. InAirRotation = Speed > 100.0f ? LastVelocityRotation : GetActorRotation(); - MainAnimInstance->OnJumped(); + + OnJumpedDelegate.Broadcast(); } void AALSBaseCharacter::Server_PlayMontage_Implementation(UAnimMontage* Montage, float PlayRate) { - MainAnimInstance->Montage_Play(Montage, PlayRate); + if (GetMesh()->GetAnimInstance()) + { + GetMesh()->GetAnimInstance()->Montage_Play(Montage, PlayRate); + } + ForceNetUpdate(); Multicast_PlayMontage(Montage, PlayRate); } void AALSBaseCharacter::Multicast_PlayMontage_Implementation(UAnimMontage* Montage, float PlayRate) { - if (!IsLocallyControlled()) + if (GetMesh()->GetAnimInstance() && !IsLocallyControlled()) { - MainAnimInstance->Montage_Play(Montage, PlayRate); + GetMesh()->GetAnimInstance()->Montage_Play(Montage, PlayRate); } } @@ -520,10 +501,15 @@ void AALSBaseCharacter::SetMovementModel() MovementData = *OutRow; } -void AALSBaseCharacter::SetHasMovementInput(bool bNewHasMovementInput) +void AALSBaseCharacter::ForceUpdateCharacterState() { - bHasMovementInput = bNewHasMovementInput; - MainAnimInstance->GetCharacterInformationMutable().bHasMovementInput = bHasMovementInput; + SetGait(DesiredGait, true); + SetStance(DesiredStance, true); + SetRotationMode(DesiredRotationMode, true); + SetViewMode(ViewMode, true); + SetOverlayState(OverlayState, true); + SetMovementState(MovementState, true); + SetMovementAction(MovementAction, true); } FALSMovementSettings AALSBaseCharacter::GetTargetMovementSettings() const @@ -596,34 +582,16 @@ bool AALSBaseCharacter::CanSprint() const return false; } -void AALSBaseCharacter::SetIsMoving(bool bNewIsMoving) -{ - bIsMoving = bNewIsMoving; - MainAnimInstance->GetCharacterInformationMutable().bIsMoving = bIsMoving; -} - FVector AALSBaseCharacter::GetMovementInput() const { return ReplicatedCurrentAcceleration; } -void AALSBaseCharacter::SetMovementInputAmount(float NewMovementInputAmount) -{ - MovementInputAmount = NewMovementInputAmount; - MainAnimInstance->GetCharacterInformationMutable().MovementInputAmount = MovementInputAmount; -} - -void AALSBaseCharacter::SetSpeed(float NewSpeed) -{ - Speed = NewSpeed; - MainAnimInstance->GetCharacterInformationMutable().Speed = Speed; -} - float AALSBaseCharacter::GetAnimCurveValue(FName CurveName) const { - if (MainAnimInstance) + if (GetMesh()->GetAnimInstance()) { - return MainAnimInstance->GetCurveValue(CurveName); + return GetMesh()->GetAnimInstance()->GetCurveValue(CurveName); } return 0.0f; @@ -672,7 +640,7 @@ FTransform AALSBaseCharacter::GetThirdPersonPivotTarget() FVector AALSBaseCharacter::GetFirstPersonCameraTarget() { - return GetMesh()->GetSocketLocation(FName(TEXT("FP_Camera"))); + return GetMesh()->GetSocketLocation(NAME_FP_Camera); } void AALSBaseCharacter::GetCameraParameters(float& TPFOVOut, float& FPFOVOut, bool& bRightShoulderOut) const @@ -682,24 +650,18 @@ void AALSBaseCharacter::GetCameraParameters(float& TPFOVOut, float& FPFOVOut, bo bRightShoulderOut = bRightShoulder; } -void AALSBaseCharacter::SetAcceleration(const FVector& NewAcceleration) -{ - Acceleration = (NewAcceleration != FVector::ZeroVector || IsLocallyControlled()) - ? NewAcceleration - : Acceleration / 2; - MainAnimInstance->GetCharacterInformationMutable().Acceleration = Acceleration; -} - void AALSBaseCharacter::RagdollUpdate(float DeltaTime) { + GetMesh()->bOnlyAllowAutonomousTickPose = false; + // Set the Last Ragdoll Velocity. - const FVector NewRagdollVel = GetMesh()->GetPhysicsLinearVelocity(FName(TEXT("root"))); + const FVector NewRagdollVel = GetMesh()->GetPhysicsLinearVelocity(NAME_root); LastRagdollVelocity = (NewRagdollVel != FVector::ZeroVector || IsLocallyControlled()) ? NewRagdollVel : LastRagdollVelocity / 2; // Use the Ragdoll Velocity to scale the ragdoll's joint strength for physical animation. - const float SpringValue = FMath::GetMappedRangeValueClamped({0.0f, 1000.0f}, {0.0f, 25000.0f}, + const float SpringValue = FMath::GetMappedRangeValueClamped({0.0f, 1000.0f}, {0.0f, 25000.0f}, LastRagdollVelocity.Size()); GetMesh()->SetAllMotorsAngularDriveParams(SpringValue, 0.0f, 0.0f, false); @@ -717,15 +679,15 @@ void AALSBaseCharacter::SetActorLocationDuringRagdoll(float DeltaTime) if (IsLocallyControlled()) { // Set the pelvis as the target location. - TargetRagdollLocation = GetMesh()->GetSocketLocation(FName(TEXT("Pelvis"))); + TargetRagdollLocation = GetMesh()->GetSocketLocation(NAME_Pelvis); if (!HasAuthority()) { Server_SetMeshLocationDuringRagdoll(TargetRagdollLocation); } } - // Determine wether the ragdoll is facing up or down and set the target rotation accordingly. - const FRotator PelvisRot = GetMesh()->GetSocketRotation(FName(TEXT("Pelvis"))); + // Determine whether the ragdoll is facing up or down and set the target rotation accordingly. + const FRotator PelvisRot = GetMesh()->GetSocketRotation(NAME_Pelvis); if (bReversedPelvis) { bRagdollFaceUp = PelvisRot.Roll > 0.0f; @@ -742,12 +704,28 @@ void AALSBaseCharacter::SetActorLocationDuringRagdoll(float DeltaTime) const FVector TraceVect(TargetRagdollLocation.X, TargetRagdollLocation.Y, TargetRagdollLocation.Z - GetCapsuleComponent()->GetScaledCapsuleHalfHeight()); + UWorld* World = GetWorld(); + check(World); + FCollisionQueryParams Params; Params.AddIgnoredActor(this); FHitResult HitResult; - GetWorld()->LineTraceSingleByChannel(HitResult, TargetRagdollLocation, TraceVect, - ECC_Visibility, Params); + const bool bHit = World->LineTraceSingleByChannel(HitResult, TargetRagdollLocation, TraceVect, + ECC_Visibility, Params); + + if (ALSDebugComponent && ALSDebugComponent->GetShowTraces()) + { + UALSDebugComponent::DrawDebugLineTraceSingle(World, + TargetRagdollLocation, + TraceVect, + EDrawDebugTrace::Type::ForOneFrame, + bHit, + HitResult, + FLinearColor::Red, + FLinearColor::Green, + 1.0f); + } bRagdollOnGround = HitResult.IsValidBlockingHit(); FVector NewRagdollLoc = TargetRagdollLocation; @@ -759,9 +737,9 @@ void AALSBaseCharacter::SetActorLocationDuringRagdoll(float DeltaTime) } if (!IsLocallyControlled()) { - ServerRagdollPull = FMath::FInterpTo(ServerRagdollPull, 750, DeltaTime, 0.6); + ServerRagdollPull = FMath::FInterpTo(ServerRagdollPull, 750.0f, DeltaTime, 0.6f); float RagdollSpeed = FVector(LastRagdollVelocity.X, LastRagdollVelocity.Y, 0).Size(); - FName RagdollSocketPullName = RagdollSpeed > 300 ? FName(TEXT("spine_03")) : FName(TEXT("pelvis")); + FName RagdollSocketPullName = RagdollSpeed > 300 ? NAME_spine_03 : NAME_pelvis; GetMesh()->AddForce( (TargetRagdollLocation - GetMesh()->GetSocketLocation(RagdollSocketPullName)) * ServerRagdollPull, RagdollSocketPullName, true); @@ -841,17 +819,16 @@ void AALSBaseCharacter::OnMovementActionChanged(const EALSMovementAction Previou void AALSBaseCharacter::OnStanceChanged(const EALSStance PreviousStance) { - MainAnimInstance->Stance = Stance; - if (CameraBehavior) { CameraBehavior->Stance = Stance; } + + MyCharacterMovementComponent->SetMovementSettings(GetTargetMovementSettings()); } void AALSBaseCharacter::OnRotationModeChanged(EALSRotationMode PreviousRotationMode) { - MainAnimInstance->RotationMode = RotationMode; if (RotationMode == EALSRotationMode::VelocityDirection && ViewMode == EALSViewMode::FirstPerson) { // If the new rotation mode is Velocity Direction and the character is in First Person, @@ -863,12 +840,12 @@ void AALSBaseCharacter::OnRotationModeChanged(EALSRotationMode PreviousRotationM { CameraBehavior->SetRotationMode(RotationMode); } + + MyCharacterMovementComponent->SetMovementSettings(GetTargetMovementSettings()); } void AALSBaseCharacter::OnGaitChanged(const EALSGait PreviousGait) { - MainAnimInstance->Gait = Gait; - if (CameraBehavior) { CameraBehavior->Gait = Gait; @@ -877,7 +854,6 @@ void AALSBaseCharacter::OnGaitChanged(const EALSGait PreviousGait) void AALSBaseCharacter::OnViewModeChanged(const EALSViewMode PreviousViewMode) { - MainAnimInstance->GetCharacterInformationMutable().ViewMode = ViewMode; if (ViewMode == EALSViewMode::ThirdPerson) { if (RotationMode == EALSRotationMode::VelocityDirection || RotationMode == EALSRotationMode::LookingDirection) @@ -900,7 +876,6 @@ void AALSBaseCharacter::OnViewModeChanged(const EALSViewMode PreviousViewMode) void AALSBaseCharacter::OnOverlayStateChanged(const EALSOverlayState PreviousState) { - MainAnimInstance->OverlayState = OverlayState; } void AALSBaseCharacter::OnVisibleMeshChanged(const USkeletalMesh* PrevVisibleMesh) @@ -917,15 +892,8 @@ void AALSBaseCharacter::OnVisibleMeshChanged(const USkeletalMesh* PrevVisibleMes } } - // Force set variables in anim bp. This ensures anim instance & character stay synchronized on mesh changes - FALSAnimCharacterInformation& AnimData = MainAnimInstance->GetCharacterInformationMutable(); - MainAnimInstance->Gait = Gait; - MainAnimInstance->Stance = Stance; - MainAnimInstance->RotationMode = RotationMode; - AnimData.ViewMode = ViewMode; - MainAnimInstance->OverlayState = OverlayState; - AnimData.PrevMovementState = PrevMovementState; - MainAnimInstance->MovementState = MovementState; + // Force set variables. This ensures anim instance & character stay synchronized on mesh changes + ForceUpdateCharacterState(); } void AALSBaseCharacter::OnStartCrouch(float HalfHeightAdjust, float ScaledHalfHeightAdjust) @@ -983,7 +951,6 @@ void AALSBaseCharacter::SetEssentialValues(float DeltaTime) ReplicatedControlRotation = GetControlRotation(); EasedMaxAcceleration = GetCharacterMovement()->GetMaxAcceleration(); } - else { EasedMaxAcceleration = GetCharacterMovement()->GetMaxAcceleration() != 0 @@ -1002,14 +969,15 @@ void AALSBaseCharacter::SetEssentialValues(float DeltaTime) const FVector CurrentVel = GetVelocity(); // Set the amount of Acceleration. - SetAcceleration((CurrentVel - PreviousVelocity) / DeltaTime); + const FVector NewAcceleration = (CurrentVel - PreviousVelocity) / DeltaTime; + Acceleration = NewAcceleration.IsNearlyZero() || IsLocallyControlled() ? NewAcceleration : Acceleration / 2; // Determine if the character is moving by getting it's speed. The Speed equals the length of the horizontal (x y) // velocity, so it does not take vertical movement into account. If the character is moving, update the last // velocity rotation. This value is saved because it might be useful to know the last orientation of movement // even after the character has stopped. - SetSpeed(CurrentVel.Size2D()); - SetIsMoving(Speed > 1.0f); + Speed = CurrentVel.Size2D(); + bIsMoving = Speed > 1.0f; if (bIsMoving) { LastVelocityRotation = CurrentVel.ToOrientationRotator(); @@ -1019,8 +987,8 @@ void AALSBaseCharacter::SetEssentialValues(float DeltaTime) // The Movement Input Amount is equal to the current acceleration divided by the max acceleration so that // it has a range of 0-1, 1 being the maximum possible amount of input, and 0 being none. // If the character has movement input, update the Last Movement Input Rotation. - SetMovementInputAmount(ReplicatedCurrentAcceleration.Size() / EasedMaxAcceleration); - SetHasMovementInput(MovementInputAmount > 0.0f); + MovementInputAmount = ReplicatedCurrentAcceleration.Size() / EasedMaxAcceleration; + bHasMovementInput = MovementInputAmount > 0.0f; if (bHasMovementInput) { LastMovementInputRotation = ReplicatedCurrentAcceleration.ToOrientationRotator(); @@ -1028,7 +996,7 @@ void AALSBaseCharacter::SetEssentialValues(float DeltaTime) // Set the Aim Yaw rate by comparing the current and previous Aim Yaw value, divided by Delta Seconds. // This represents the speed the camera is rotating left to right. - SetAimYawRate(FMath::Abs((AimingRotation.Yaw - PreviousAimYaw) / DeltaTime)); + AimYawRate = FMath::Abs((AimingRotation.Yaw - PreviousAimYaw) / DeltaTime); } void AALSBaseCharacter::UpdateCharacterMovement() @@ -1044,12 +1012,8 @@ void AALSBaseCharacter::UpdateCharacterMovement() SetGait(ActualGait); } - // Get the Current Movement Settings and pass it through to the movement component. - MyCharacterMovementComponent->SetMovementSettings(GetTargetMovementSettings()); - // Update the Character Max Walk Speed to the configured speeds based on the currently Allowed Gait. - const float NewMaxSpeed = MyCharacterMovementComponent->CurrentMovementSettings.GetSpeedForGait(AllowedGait); - MyCharacterMovementComponent->SetMaxWalkingSpeed(NewMaxSpeed); + MyCharacterMovementComponent->SetAllowedGait(AllowedGait); } void AALSBaseCharacter::UpdateGroundedRotation(float DeltaTime) @@ -1077,7 +1041,7 @@ void AALSBaseCharacter::UpdateGroundedRotation(float DeltaTime) else { // Walking or Running.. - const float YawOffsetCurveVal = MainAnimInstance->GetCurveValue(FName(TEXT("YawOffset"))); + const float YawOffsetCurveVal = GetAnimCurveValue(NAME_YawOffset); YawValue = AimingRotation.Yaw + YawOffsetCurveVal; } SmoothCharacterRotation({0.0f, YawValue, 0.0f}, 500.0f, GroundedRotationRate, DeltaTime); @@ -1102,7 +1066,7 @@ void AALSBaseCharacter::UpdateGroundedRotation(float DeltaTime) // The Rotation Amount curve defines how much rotation should be applied each frame, // and is calculated for animations that are animated at 30fps. - const float RotAmountCurve = MainAnimInstance->GetCurveValue(FName(TEXT("RotationAmount"))); + const float RotAmountCurve = GetAnimCurveValue(NAME_RotationAmount); if (FMath::Abs(RotAmountCurve) > 0.001f) { @@ -1179,7 +1143,7 @@ EALSGait AALSBaseCharacter::GetActualGait(EALSGait AllowedGait) const { // Get the Actual Gait. This is calculated by the actual movement of the character, and so it can be different // from the desired gait or allowed gait. For instance, if the Allowed Gait becomes walking, - // the Actual gait will still be running untill the character decelerates to the walking speed. + // the Actual gait will still be running until the character decelerates to the walking speed. const float LocWalkSpeed = MyCharacterMovementComponent->CurrentMovementSettings.WalkSpeed; const float LocRunSpeed = MyCharacterMovementComponent->CurrentMovementSettings.RunSpeed; @@ -1220,7 +1184,7 @@ float AALSBaseCharacter::CalculateGroundedRotationRate() const const float MappedSpeedVal = MyCharacterMovementComponent->GetMappedSpeed(); const float CurveVal = MyCharacterMovementComponent->CurrentMovementSettings.RotationRateCurve->GetFloatValue(MappedSpeedVal); - const float ClampedAimYawRate = FMath::GetMappedRangeValueClamped({0.0f, 300.0f}, {1.0f, 3.0f}, AimYawRate); + const float ClampedAimYawRate = FMath::GetMappedRangeValueClamped({0.0f, 300.0f}, {1.0f, 3.0f}, AimYawRate); return CurveVal * ClampedAimYawRate; } @@ -1239,126 +1203,104 @@ void AALSBaseCharacter::LimitRotation(float AimYawMin, float AimYawMax, float In } } -void AALSBaseCharacter::GetControlForwardRightVector(FVector& Forward, FVector& Right) const -{ - const FRotator ControlRot(0.0f, AimingRotation.Yaw, 0.0f); - Forward = GetInputAxisValue("MoveForward/Backwards") * UKismetMathLibrary::GetForwardVector(ControlRot); - Right = GetInputAxisValue("MoveRight/Left") * UKismetMathLibrary::GetRightVector(ControlRot); -} - -FVector AALSBaseCharacter::GetPlayerMovementInput() const -{ - FVector Forward = FVector::ZeroVector; - FVector Right = FVector::ZeroVector; - GetControlForwardRightVector(Forward, Right); - return (Forward + Right).GetSafeNormal(); -} - -void AALSBaseCharacter::PlayerForwardMovementInput(float Value) +void AALSBaseCharacter::ForwardMovementAction_Implementation(float Value) { if (MovementState == EALSMovementState::Grounded || MovementState == EALSMovementState::InAir) { // Default camera relative movement behavior - const float Scale = UALSMathLibrary::FixDiagonalGamepadValues(Value, GetInputAxisValue("MoveRight/Left")).Key; const FRotator DirRotator(0.0f, AimingRotation.Yaw, 0.0f); - AddMovementInput(UKismetMathLibrary::GetForwardVector(DirRotator), Scale); + AddMovementInput(UKismetMathLibrary::GetForwardVector(DirRotator), Value); } } -void AALSBaseCharacter::PlayerRightMovementInput(float Value) +void AALSBaseCharacter::RightMovementAction_Implementation(float Value) { if (MovementState == EALSMovementState::Grounded || MovementState == EALSMovementState::InAir) { // Default camera relative movement behavior - const float Scale = UALSMathLibrary::FixDiagonalGamepadValues(GetInputAxisValue("MoveForward/Backwards"), Value) - .Value; const FRotator DirRotator(0.0f, AimingRotation.Yaw, 0.0f); - AddMovementInput(UKismetMathLibrary::GetRightVector(DirRotator), Scale); + AddMovementInput(UKismetMathLibrary::GetRightVector(DirRotator), Value); } } -void AALSBaseCharacter::PlayerCameraUpInput(float Value) +void AALSBaseCharacter::CameraUpAction_Implementation(float Value) { AddControllerPitchInput(LookUpDownRate * Value); } -void AALSBaseCharacter::PlayerCameraRightInput(float Value) +void AALSBaseCharacter::CameraRightAction_Implementation(float Value) { AddControllerYawInput(LookLeftRightRate * Value); } -void AALSBaseCharacter::JumpPressedAction() +void AALSBaseCharacter::JumpAction_Implementation(bool bValue) { - // Jump Action: Press "Jump Action" to end the ragdoll if ragdolling, stand up if crouching, or jump if standing. - - if (JumpPressedDelegate.IsBound()) + if (bValue) { - JumpPressedDelegate.Broadcast(); - } + // Jump Action: Press "Jump Action" to end the ragdoll if ragdolling, stand up if crouching, or jump if standing. + if (JumpPressedDelegate.IsBound()) + { + JumpPressedDelegate.Broadcast(); + } - if (MovementAction == EALSMovementAction::None) - { - if (MovementState == EALSMovementState::Grounded) + if (MovementAction == EALSMovementAction::None) { - if (Stance == EALSStance::Standing) + if (MovementState == EALSMovementState::Grounded) { - Jump(); + if (Stance == EALSStance::Standing) + { + Jump(); + } + else if (Stance == EALSStance::Crouching) + { + UnCrouch(); + } } - else if (Stance == EALSStance::Crouching) + else if (MovementState == EALSMovementState::Ragdoll) { - UnCrouch(); + ReplicatedRagdollEnd(); } } - else if (MovementState == EALSMovementState::Ragdoll) - { - ReplicatedRagdollEnd(); - } + } + else + { + StopJumping(); } } -void AALSBaseCharacter::JumpReleasedAction() -{ - StopJumping(); -} - -void AALSBaseCharacter::SprintPressedAction() -{ - SetDesiredGait(EALSGait::Sprinting); -} - -void AALSBaseCharacter::SprintReleasedAction() -{ - SetDesiredGait(EALSGait::Running); -} - -void AALSBaseCharacter::AimPressedAction() -{ - // AimAction: Hold "AimAction" to enter the aiming mode, release to revert back the desired rotation mode. - SetRotationMode(EALSRotationMode::Aiming); -} - -void AALSBaseCharacter::AimReleasedAction() +void AALSBaseCharacter::SprintAction_Implementation(bool bValue) { - if (ViewMode == EALSViewMode::ThirdPerson) + if (bValue) { - SetRotationMode(DesiredRotationMode); + SetDesiredGait(EALSGait::Sprinting); } - else if (ViewMode == EALSViewMode::FirstPerson) + else { - SetRotationMode(EALSRotationMode::LookingDirection); + SetDesiredGait(EALSGait::Running); } } -void AALSBaseCharacter::CameraPressedAction() +void AALSBaseCharacter::AimAction_Implementation(bool bValue) { - UWorld* World = GetWorld(); - check(World); - CameraActionPressedTime = World->GetTimeSeconds(); - GetWorldTimerManager().SetTimer(OnCameraModeSwapTimer, this, - &AALSBaseCharacter::OnSwitchCameraMode, ViewModeSwitchHoldTime, false); + if (bValue) + { + // AimAction: Hold "AimAction" to enter the aiming mode, release to revert back the desired rotation mode. + SetRotationMode(EALSRotationMode::Aiming); + } + else + { + if (ViewMode == EALSViewMode::ThirdPerson) + { + SetRotationMode(DesiredRotationMode); + } + else if (ViewMode == EALSViewMode::FirstPerson) + { + SetRotationMode(EALSRotationMode::LookingDirection); + } + } } -void AALSBaseCharacter::CameraReleasedAction() +void AALSBaseCharacter::CameraTapAction_Implementation() { if (ViewMode == EALSViewMode::FirstPerson) { @@ -1366,17 +1308,11 @@ void AALSBaseCharacter::CameraReleasedAction() return; } - UWorld* World = GetWorld(); - check(World); - if (World->GetTimeSeconds() - CameraActionPressedTime < ViewModeSwitchHoldTime) - { - // Switch shoulders - SetRightShoulder(!bRightShoulder); - GetWorldTimerManager().ClearTimer(OnCameraModeSwapTimer); // Prevent mode change - } + // Switch shoulders + SetRightShoulder(!bRightShoulder); } -void AALSBaseCharacter::OnSwitchCameraMode() +void AALSBaseCharacter::CameraHeldAction_Implementation() { // Switch camera mode if (ViewMode == EALSViewMode::FirstPerson) @@ -1389,8 +1325,7 @@ void AALSBaseCharacter::OnSwitchCameraMode() } } - -void AALSBaseCharacter::StancePressedAction() +void AALSBaseCharacter::StanceAction_Implementation() { // Stance Action: Press "Stance Action" to toggle Standing / Crouching, double tap to Roll. @@ -1438,7 +1373,7 @@ void AALSBaseCharacter::StancePressedAction() // Notice: MovementState == EALSMovementState::InAir case is removed } -void AALSBaseCharacter::WalkPressedAction() +void AALSBaseCharacter::WalkAction_Implementation() { if (DesiredGait == EALSGait::Walking) { @@ -1450,7 +1385,7 @@ void AALSBaseCharacter::WalkPressedAction() } } -void AALSBaseCharacter::RagdollPressedAction() +void AALSBaseCharacter::RagdollAction_Implementation() { // Ragdoll Action: Press "Ragdoll Action" to toggle the ragdoll state on or off. @@ -1464,7 +1399,7 @@ void AALSBaseCharacter::RagdollPressedAction() } } -void AALSBaseCharacter::VelocityDirectionPressedAction() +void AALSBaseCharacter::VelocityDirectionAction_Implementation() { // Select Rotation Mode: Switch the desired (default) rotation mode to Velocity or Looking Direction. // This will be the mode the character reverts back to when un-aiming @@ -1472,7 +1407,7 @@ void AALSBaseCharacter::VelocityDirectionPressedAction() SetRotationMode(EALSRotationMode::VelocityDirection); } -void AALSBaseCharacter::LookingDirectionPressedAction() +void AALSBaseCharacter::LookingDirectionAction_Implementation() { SetDesiredRotationMode(EALSRotationMode::LookingDirection); SetRotationMode(EALSRotationMode::LookingDirection); @@ -1517,7 +1452,7 @@ void AALSBaseCharacter::OnRep_OverlayState(EALSOverlayState PrevOverlayState) OnOverlayStateChanged(PrevOverlayState); } -void AALSBaseCharacter::OnRep_VisibleMesh(USkeletalMesh* NewVisibleMesh) +void AALSBaseCharacter::OnRep_VisibleMesh(const USkeletalMesh* PreviousSkeletalMesh) { - OnVisibleMeshChanged(NewVisibleMesh); + OnVisibleMeshChanged(PreviousSkeletalMesh); } diff --git a/Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp b/Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp index d181ec7e8..f5ded888c 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSCharacter.cpp @@ -1,13 +1,11 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/ALSCharacter.h" - +#include "Components/StaticMeshComponent.h" +#include "Engine/SkeletalMesh.h" +#include "Components/SkeletalMeshComponent.h" #include "Engine/StaticMesh.h" #include "AI/ALSAIController.h" #include "Kismet/GameplayStatics.h" diff --git a/Source/ALSV4_CPP/Private/Character/ALSCharacterMovementComponent.cpp b/Source/ALSV4_CPP/Private/Character/ALSCharacterMovementComponent.cpp index d9dc572d2..a7a86a409 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSCharacterMovementComponent.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSCharacterMovementComponent.cpp @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Haziq Fadhil -// Contributors: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/ALSCharacterMovementComponent.h" @@ -29,8 +25,11 @@ void UALSCharacterMovementComponent::OnMovementUpdated(float DeltaTime, const FV // Set Movement Settings if (bRequestMovementSettingsChange) { - MaxWalkSpeed = NewMaxWalkSpeed; - MaxWalkSpeedCrouched = NewMaxWalkSpeed; + const float UpdateMaxWalkSpeed = CurrentMovementSettings.GetSpeedForGait(AllowedGait); + MaxWalkSpeed = UpdateMaxWalkSpeed; + MaxWalkSpeedCrouched = UpdateMaxWalkSpeed; + + bRequestMovementSettingsChange = false; } } @@ -95,6 +94,7 @@ void UALSCharacterMovementComponent::FSavedMove_My::Clear() Super::Clear(); bSavedRequestMovementSettingsChange = false; + SavedAllowedGait = EALSGait::Walking; } uint8 UALSCharacterMovementComponent::FSavedMove_My::GetCompressedFlags() const @@ -116,12 +116,22 @@ void UALSCharacterMovementComponent::FSavedMove_My::SetMoveFor(ACharacter* Chara { Super::SetMoveFor(Character, InDeltaTime, NewAccel, ClientData); - UALSCharacterMovementComponent* CharacterMovement = Cast( - Character->GetCharacterMovement()); + UALSCharacterMovementComponent* CharacterMovement = Cast(Character->GetCharacterMovement()); if (CharacterMovement) { bSavedRequestMovementSettingsChange = CharacterMovement->bRequestMovementSettingsChange; - MaxSpeed = CharacterMovement->NewMaxWalkSpeed; + SavedAllowedGait = CharacterMovement->AllowedGait; + } +} + +void UALSCharacterMovementComponent::FSavedMove_My::PrepMoveFor(ACharacter* Character) +{ + Super::PrepMoveFor(Character); + + UALSCharacterMovementComponent* CharacterMovement = Cast(Character->GetCharacterMovement()); + if (CharacterMovement) + { + CharacterMovement->AllowedGait = SavedAllowedGait; } } @@ -136,9 +146,9 @@ FSavedMovePtr UALSCharacterMovementComponent::FNetworkPredictionData_Client_My:: return MakeShared(); } -void UALSCharacterMovementComponent::Server_SetMaxWalkingSpeed_Implementation(const float UpdateMaxWalkSpeed) +void UALSCharacterMovementComponent::Server_SetAllowedGait_Implementation(const EALSGait NewAllowedGait) { - NewMaxWalkSpeed = UpdateMaxWalkSpeed; + AllowedGait = NewAllowedGait; } float UALSCharacterMovementComponent::GetMappedSpeed() const @@ -154,36 +164,41 @@ float UALSCharacterMovementComponent::GetMappedSpeed() const if (Speed > LocRunSpeed) { - return FMath::GetMappedRangeValueClamped({LocRunSpeed, LocSprintSpeed}, {2.0f, 3.0f}, Speed); + return FMath::GetMappedRangeValueClamped({LocRunSpeed, LocSprintSpeed}, {2.0f, 3.0f}, Speed); } if (Speed > LocWalkSpeed) { - return FMath::GetMappedRangeValueClamped({LocWalkSpeed, LocRunSpeed}, {1.0f, 2.0f}, Speed); + return FMath::GetMappedRangeValueClamped({LocWalkSpeed, LocRunSpeed}, {1.0f, 2.0f}, Speed); } - return FMath::GetMappedRangeValueClamped({0.0f, LocWalkSpeed}, {0.0f, 1.0f}, Speed); + return FMath::GetMappedRangeValueClamped({0.0f, LocWalkSpeed}, {0.0f, 1.0f}, Speed); } void UALSCharacterMovementComponent::SetMovementSettings(FALSMovementSettings NewMovementSettings) { // Set the current movement settings from the owner CurrentMovementSettings = NewMovementSettings; + bRequestMovementSettingsChange = true; } -void UALSCharacterMovementComponent::SetMaxWalkingSpeed(float UpdateMaxWalkSpeed) +void UALSCharacterMovementComponent::SetAllowedGait(EALSGait NewAllowedGait) { - if (UpdateMaxWalkSpeed != NewMaxWalkSpeed) + if (AllowedGait != NewAllowedGait) { if (PawnOwner->IsLocallyControlled()) { - NewMaxWalkSpeed = UpdateMaxWalkSpeed; - Server_SetMaxWalkingSpeed(UpdateMaxWalkSpeed); + AllowedGait = NewAllowedGait; + if (GetCharacterOwner()->GetLocalRole() == ROLE_AutonomousProxy) + { + Server_SetAllowedGait(NewAllowedGait); + } bRequestMovementSettingsChange = true; return; } if (!PawnOwner->HasAuthority()) { + const float UpdateMaxWalkSpeed = CurrentMovementSettings.GetSpeedForGait(AllowedGait); MaxWalkSpeed = UpdateMaxWalkSpeed; MaxWalkSpeedCrouched = UpdateMaxWalkSpeed; } diff --git a/Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp b/Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp index c2fedaa98..fece35901 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSPlayerCameraManager.cpp @@ -1,22 +1,37 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/ALSPlayerCameraManager.h" - +#include "Engine/World.h" +#include "Components/SkeletalMeshComponent.h" #include "Character/ALSBaseCharacter.h" #include "Character/ALSPlayerController.h" #include "Character/Animation/ALSPlayerCameraBehavior.h" +#include "Components/ALSDebugComponent.h" + #include "Kismet/KismetMathLibrary.h" + +const FName NAME_CameraBehavior(TEXT("CameraBehavior")); +const FName NAME_CameraOffset_X(TEXT("CameraOffset_X")); +const FName NAME_CameraOffset_Y(TEXT("CameraOffset_Y")); +const FName NAME_CameraOffset_Z(TEXT("CameraOffset_Z")); +const FName NAME_Override_Debug(TEXT("Override_Debug")); +const FName NAME_PivotLagSpeed_X(TEXT("PivotLagSpeed_X")); +const FName NAME_PivotLagSpeed_Y(TEXT("PivotLagSpeed_Y")); +const FName NAME_PivotLagSpeed_Z(TEXT("PivotLagSpeed_Z")); +const FName NAME_PivotOffset_X(TEXT("PivotOffset_X")); +const FName NAME_PivotOffset_Y(TEXT("PivotOffset_Y")); +const FName NAME_PivotOffset_Z(TEXT("PivotOffset_Z")); +const FName NAME_RotationLagSpeed(TEXT("RotationLagSpeed")); +const FName NAME_Weight_FirstPerson(TEXT("Weight_FirstPerson")); + + AALSPlayerCameraManager::AALSPlayerCameraManager() { - CameraBehavior = CreateDefaultSubobject(FName(TEXT("CameraBehavior"))); + CameraBehavior = CreateDefaultSubobject(NAME_CameraBehavior); CameraBehavior->SetupAttachment(GetRootComponent()); CameraBehavior->bHiddenInGame = true; } @@ -45,6 +60,8 @@ void AALSPlayerCameraManager::OnPossess(AALSBaseCharacter* NewCharacter) const FVector& TPSLoc = ControlledCharacter->GetThirdPersonPivotTarget().GetLocation(); SetActorLocation(TPSLoc); SmoothedPivotTarget.SetLocation(TPSLoc); + + ALSDebugComponent = ControlledCharacter->FindComponentByClass(); } float AALSPlayerCameraManager::GetCameraBehaviorParam(FName CurveName) const @@ -67,11 +84,22 @@ void AALSPlayerCameraManager::UpdateViewTargetInternal(FTViewTarget& OutVT, floa FRotator OutRotation; float OutFOV; - if (CustomCameraBehavior(DeltaTime, OutLocation, OutRotation, OutFOV)) + if (OutVT.Target->IsA()) { - OutVT.POV.Location = OutLocation; - OutVT.POV.Rotation = OutRotation; - OutVT.POV.FOV = OutFOV; + if (CustomCameraBehavior(DeltaTime, OutLocation, OutRotation, OutFOV)) + { + OutVT.POV.Location = OutLocation; + OutVT.POV.Rotation = OutRotation; + OutVT.POV.FOV = OutFOV; + } + else + { + OutVT.Target->CalcCamera(DeltaTime, OutVT.POV); + } + } + else + { + OutVT.Target->CalcCamera(DeltaTime, OutVT.POV); } } } @@ -111,16 +139,16 @@ bool AALSPlayerCameraManager::CustomCameraBehavior(float DeltaTime, FVector& Loc // Step 2: Calculate Target Camera Rotation. Use the Control Rotation and interpolate for smooth camera rotation. const FRotator& InterpResult = FMath::RInterpTo(GetCameraRotation(), GetOwningPlayerController()->GetControlRotation(), DeltaTime, - GetCameraBehaviorParam(FName(TEXT("RotationLagSpeed")))); + GetCameraBehaviorParam(NAME_RotationLagSpeed)); TargetCameraRotation = UKismetMathLibrary::RLerp(InterpResult, DebugViewRotation, GetCameraBehaviorParam(TEXT("Override_Debug")), true); // Step 3: Calculate the Smoothed Pivot Target (Orange Sphere). // Get the 3P Pivot Target (Green Sphere) and interpolate using axis independent lag for maximum control. - const FVector LagSpd(GetCameraBehaviorParam(FName(TEXT("PivotLagSpeed_X"))), - GetCameraBehaviorParam(FName(TEXT("PivotLagSpeed_Y"))), - GetCameraBehaviorParam(FName(TEXT("PivotLagSpeed_Z")))); + const FVector LagSpd(GetCameraBehaviorParam(NAME_PivotLagSpeed_X), + GetCameraBehaviorParam(NAME_PivotLagSpeed_Y), + GetCameraBehaviorParam(NAME_PivotLagSpeed_Z)); const FVector& AxisIndpLag = CalculateAxisIndependentLag(SmoothedPivotTarget.GetLocation(), PivotTarget.GetLocation(), TargetCameraRotation, LagSpd, @@ -135,22 +163,22 @@ bool AALSPlayerCameraManager::CustomCameraBehavior(float DeltaTime, FVector& Loc PivotLocation = SmoothedPivotTarget.GetLocation() + UKismetMathLibrary::GetForwardVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam( - FName(TEXT("PivotOffset_X"))) + + NAME_PivotOffset_X) + UKismetMathLibrary::GetRightVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam( - FName(TEXT("PivotOffset_Y"))) + + NAME_PivotOffset_Y) + UKismetMathLibrary::GetUpVector(SmoothedPivotTarget.Rotator()) * GetCameraBehaviorParam( - FName(TEXT("PivotOffset_Z"))); + NAME_PivotOffset_Z); // Step 5: Calculate Target Camera Location. Get the Pivot location and apply camera relative offsets. TargetCameraLocation = UKismetMathLibrary::VLerp( PivotLocation + UKismetMathLibrary::GetForwardVector(TargetCameraRotation) * GetCameraBehaviorParam( - FName(TEXT("CameraOffset_X"))) + - UKismetMathLibrary::GetRightVector(TargetCameraRotation) * GetCameraBehaviorParam(FName(TEXT("CameraOffset_Y"))) + NAME_CameraOffset_X) + + UKismetMathLibrary::GetRightVector(TargetCameraRotation) * GetCameraBehaviorParam(NAME_CameraOffset_Y) + - UKismetMathLibrary::GetUpVector(TargetCameraRotation) * GetCameraBehaviorParam(FName(TEXT("CameraOffset_Z"))), + UKismetMathLibrary::GetUpVector(TargetCameraRotation) * GetCameraBehaviorParam(NAME_CameraOffset_Z), PivotTarget.GetLocation() + DebugViewOffset, - GetCameraBehaviorParam(FName(TEXT("Override_Debug")))); + GetCameraBehaviorParam(NAME_Override_Debug)); // Step 6: Trace for an object between the camera and character to apply a corrective offset. // Trace origins are set within the Character BP via the Camera Interface. @@ -167,8 +195,23 @@ bool AALSPlayerCameraManager::CustomCameraBehavior(float DeltaTime, FVector& Loc Params.AddIgnoredActor(ControlledCharacter); FHitResult HitResult; - World->SweepSingleByChannel(HitResult, TraceOrigin, TargetCameraLocation, FQuat::Identity, - TraceChannel, FCollisionShape::MakeSphere(TraceRadius), Params); + const FCollisionShape SphereCollisionShape = FCollisionShape::MakeSphere(TraceRadius); + const bool bHit = World->SweepSingleByChannel(HitResult, TraceOrigin, TargetCameraLocation, FQuat::Identity, + TraceChannel, SphereCollisionShape, Params); + + if (ALSDebugComponent && ALSDebugComponent->GetShowTraces()) + { + UALSDebugComponent::DrawDebugSphereTraceSingle(World, + TraceOrigin, + TargetCameraLocation, + SphereCollisionShape, + EDrawDebugTrace::Type::ForOneFrame, + bHit, + HitResult, + FLinearColor::Red, + FLinearColor::Green, + 5.0f); + } if (HitResult.IsValidBlockingHit()) { @@ -181,17 +224,17 @@ bool AALSPlayerCameraManager::CustomCameraBehavior(float DeltaTime, FVector& Loc const FTransform& MixedTransform = UKismetMathLibrary::TLerp(TargetCameraTransform, FPTargetCameraTransform, GetCameraBehaviorParam( - FName(TEXT("Weight_FirstPerson")))); + NAME_Weight_FirstPerson)); const FTransform& TargetTransform = UKismetMathLibrary::TLerp(MixedTransform, FTransform(DebugViewRotation, TargetCameraLocation, FVector::OneVector), GetCameraBehaviorParam( - FName(TEXT("Override_Debug")))); + NAME_Override_Debug)); Location = TargetTransform.GetLocation(); Rotation = TargetTransform.Rotator(); - FOV = FMath::Lerp(TPFOV, FPFOV, GetCameraBehaviorParam(FName(TEXT("Weight_FirstPerson")))); + FOV = FMath::Lerp(TPFOV, FPFOV, GetCameraBehaviorParam(NAME_Weight_FirstPerson)); return true; } diff --git a/Source/ALSV4_CPP/Private/Character/ALSPlayerController.cpp b/Source/ALSV4_CPP/Private/Character/ALSPlayerController.cpp index 1168ce6fa..ce68c74ce 100644 --- a/Source/ALSV4_CPP/Private/Character/ALSPlayerController.cpp +++ b/Source/ALSV4_CPP/Private/Character/ALSPlayerController.cpp @@ -1,12 +1,14 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: Drakynfly +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/ALSPlayerController.h" + +#include "EnhancedInputComponent.h" +#include "EnhancedInputSubsystems.h" +#include "InputMappingContext.h" +#include "Engine/LocalPlayer.h" +#include "AI/ALSAIController.h" #include "Character/ALSCharacter.h" #include "Character/ALSPlayerCameraManager.h" #include "Components/ALSDebugComponent.h" @@ -21,7 +23,16 @@ void AALSPlayerController::OnPossess(APawn* NewPawn) // Servers want to setup camera only in listen servers. SetupCamera(); } - SetupDebugInputs(); + + SetupInputs(); + + if (!IsValid(PossessedCharacter)) return; + + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->OnPlayerControllerInitialized(this); + } } void AALSPlayerController::OnRep_Pawn() @@ -29,14 +40,75 @@ void AALSPlayerController::OnRep_Pawn() Super::OnRep_Pawn(); PossessedCharacter = Cast(GetPawn()); SetupCamera(); + SetupInputs(); + + if (!PossessedCharacter) return; + + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->OnPlayerControllerInitialized(this); + } +} + +void AALSPlayerController::SetupInputComponent() +{ + Super::SetupInputComponent(); + + UEnhancedInputComponent* EnhancedInputComponent = Cast(InputComponent); + if (EnhancedInputComponent) + { + EnhancedInputComponent->ClearActionEventBindings(); + EnhancedInputComponent->ClearActionValueBindings(); + EnhancedInputComponent->ClearDebugKeyBindings(); + + BindActions(DefaultInputMappingContext); + BindActions(DebugInputMappingContext); + } + else + { + UE_LOG(LogTemp, Fatal, TEXT("ALS Community requires Enhanced Input System to be activated in project settings to function properly")); + } } -void AALSPlayerController::BeginPlayingState() +void AALSPlayerController::BindActions(UInputMappingContext* Context) { - Super::BeginPlayingState(); - if (GetLocalRole() == ROLE_AutonomousProxy) + if (Context) { - SetupDebugInputs(); + const TArray& Mappings = Context->GetMappings(); + UEnhancedInputComponent* EnhancedInputComponent = Cast(InputComponent); + if (EnhancedInputComponent) + { + // There may be more than one keymapping assigned to one action. So, first filter duplicate action entries to prevent multiple delegate bindings + TSet UniqueActions; + for (const FEnhancedActionKeyMapping& Keymapping : Mappings) + { + UniqueActions.Add(Keymapping.Action); + } + for (const UInputAction* UniqueAction : UniqueActions) + { + EnhancedInputComponent->BindAction(UniqueAction, ETriggerEvent::Triggered, Cast(this), UniqueAction->GetFName()); + } + } + } +} + +void AALSPlayerController::SetupInputs() +{ + if (PossessedCharacter) + { + if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(GetLocalPlayer())) + { + FModifyContextOptions Options; + Options.bForceImmediately = 1; + Subsystem->AddMappingContext(DefaultInputMappingContext, 1, Options); + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + // Do only if we have debug component + Subsystem->AddMappingContext(DebugInputMappingContext, 0, Options); + } + } } } @@ -50,26 +122,246 @@ void AALSPlayerController::SetupCamera() } } -void AALSPlayerController::SetupDebugInputs() +void AALSPlayerController::ForwardMovementAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->ForwardMovementAction(Value.GetMagnitude()); + } +} + +void AALSPlayerController::RightMovementAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->RightMovementAction(Value.GetMagnitude()); + } +} + +void AALSPlayerController::CameraUpAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->CameraUpAction(Value.GetMagnitude()); + } +} + +void AALSPlayerController::CameraRightAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->CameraRightAction(Value.GetMagnitude()); + } +} + +void AALSPlayerController::JumpAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->JumpAction(Value.Get()); + } +} + +void AALSPlayerController::SprintAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->SprintAction(Value.Get()); + } +} + +void AALSPlayerController::AimAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->AimAction(Value.Get()); + } +} + +void AALSPlayerController::CameraTapAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->CameraTapAction(); + } +} + +void AALSPlayerController::CameraHeldAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + PossessedCharacter->CameraHeldAction(); + } +} + +void AALSPlayerController::StanceAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + PossessedCharacter->StanceAction(); + } +} + +void AALSPlayerController::WalkAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + PossessedCharacter->WalkAction(); + } +} + +void AALSPlayerController::RagdollAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + PossessedCharacter->RagdollAction(); + } +} + +void AALSPlayerController::VelocityDirectionAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + PossessedCharacter->VelocityDirectionAction(); + } +} + +void AALSPlayerController::LookingDirectionAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + PossessedCharacter->LookingDirectionAction(); + } +} + +void AALSPlayerController::DebugToggleHudAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->ToggleHud(); + } + } +} + +void AALSPlayerController::DebugToggleDebugViewAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->ToggleDebugView(); + } + } +} + +void AALSPlayerController::DebugToggleTracesAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->ToggleTraces(); + } + } +} + +void AALSPlayerController::DebugToggleShapesAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->ToggleDebugShapes(); + } + } +} + +void AALSPlayerController::DebugToggleLayerColorsAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->ToggleLayerColors(); + } + } +} + +void AALSPlayerController::DebugToggleCharacterInfoAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->ToggleCharacterInfo(); + } + } +} + +void AALSPlayerController::DebugToggleSlomoAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->ToggleSlomo(); + } + } +} + +void AALSPlayerController::DebugFocusedCharacterCycleAction(const FInputActionValue& Value) { - // Bind inputs for debugging if (PossessedCharacter) { - UActorComponent* Comp = PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass()); - if (Comp) + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) { - UALSDebugComponent* DebugComp = Cast(Comp); - if (InputComponent && DebugComp) - { - InputComponent->BindKey(FKey("Tab"), EInputEvent::IE_Pressed, DebugComp, &UALSDebugComponent::ToggleHud); - InputComponent->BindKey(FKey("V"), EInputEvent::IE_Pressed, DebugComp, &UALSDebugComponent::ToggleDebugView); - InputComponent->BindKey(FKey("T"), EInputEvent::IE_Pressed, DebugComp, &UALSDebugComponent::ToggleTraces); - InputComponent->BindKey(FKey("Y"), EInputEvent::IE_Pressed, DebugComp, &UALSDebugComponent::ToggleDebugShapes); - InputComponent->BindKey(FKey("U"), EInputEvent::IE_Pressed, DebugComp, &UALSDebugComponent::ToggleLayerColors); - InputComponent->BindKey(FKey("I"), EInputEvent::IE_Pressed, DebugComp, &UALSDebugComponent::ToggleCharacterInfo); - InputComponent->BindKey(FKey("Z"), EInputEvent::IE_Pressed, DebugComp, &UALSDebugComponent::ToggleSlomo); - InputComponent->BindKey(FKey("M"), EInputEvent::IE_Pressed, DebugComp, &UALSDebugComponent::ToggleDebugMesh); - } + DebugComp->FocusedDebugCharacterCycle(Value.GetMagnitude() > 0); + } + } +} + +void AALSPlayerController::DebugToggleMeshAction(const FInputActionValue& Value) +{ + if (PossessedCharacter && Value.Get()) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->ToggleDebugMesh(); + } + } +} + +void AALSPlayerController::DebugOpenOverlayMenuAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->OpenOverlayMenu(Value.Get()); + } + } +} + +void AALSPlayerController::DebugOverlayMenuCycleAction(const FInputActionValue& Value) +{ + if (PossessedCharacter) + { + UALSDebugComponent* DebugComp = Cast(PossessedCharacter->GetComponentByClass(UALSDebugComponent::StaticClass())); + if (DebugComp) + { + DebugComp->OverlayMenuCycle(Value.GetMagnitude() > 0); } } } diff --git a/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp b/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp index 034568d31..60f9e261b 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/ALSCharacterAnimInstance.cpp @@ -1,22 +1,69 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: Haziq Fadhil, Jens Bjarne Myhre +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/Animation/ALSCharacterAnimInstance.h" + #include "Character/ALSBaseCharacter.h" #include "Library/ALSMathLibrary.h" +#include "Components/ALSDebugComponent.h" +#include "Curves/CurveFloat.h" #include "Curves/CurveVector.h" +#include "Engine/World.h" +#include "TimerManager.h" +#include "Components/SkeletalMeshComponent.h" #include "Components/CapsuleComponent.h" #include "GameFramework/CharacterMovementComponent.h" + +static const FName NAME_BasePose_CLF(TEXT("BasePose_CLF")); +static const FName NAME_BasePose_N(TEXT("BasePose_N")); +static const FName NAME_Enable_FootIK_R(TEXT("Enable_FootIK_R")); +static const FName NAME_Enable_FootIK_L(TEXT("Enable_FootIK_L")); +static const FName NAME_Enable_HandIK_L(TEXT("Enable_HandIK_L")); +static const FName NAME_Enable_HandIK_R(TEXT("Enable_HandIK_R")); +static const FName NAME_Enable_Transition(TEXT("Enable_Transition")); +static const FName NAME_FootLock_L(TEXT("FootLock_L")); +static const FName NAME_FootLock_R(TEXT("FootLock_R")); +static const FName NAME_Grounded___Slot(TEXT("Grounded Slot")); +static const FName NAME_Layering_Arm_L(TEXT("Layering_Arm_L")); +static const FName NAME_Layering_Arm_L_Add(TEXT("Layering_Arm_L_Add")); +static const FName NAME_Layering_Arm_L_LS(TEXT("Layering_Arm_L_LS")); +static const FName NAME_Layering_Arm_R(TEXT("Layering_Arm_R")); +static const FName NAME_Layering_Arm_R_Add(TEXT("Layering_Arm_R_Add")); +static const FName NAME_Layering_Arm_R_LS(TEXT("Layering_Arm_R_LS")); +static const FName NAME_Layering_Hand_L(TEXT("Layering_Hand_L")); +static const FName NAME_Layering_Hand_R(TEXT("Layering_Hand_R")); +static const FName NAME_Layering_Head_Add(TEXT("Layering_Head_Add")); +static const FName NAME_Layering_Spine_Add(TEXT("Layering_Spine_Add")); +static const FName NAME_Mask_AimOffset(TEXT("Mask_AimOffset")); +static const FName NAME_Mask_LandPrediction(TEXT("Mask_LandPrediction")); +static const FName NAME__ALSCharacterAnimInstance__RotationAmount(TEXT("RotationAmount")); +static const FName NAME_VB___foot_target_l(TEXT("VB foot_target_l")); +static const FName NAME_VB___foot_target_r(TEXT("VB foot_target_r")); +static const FName NAME_W_Gait(TEXT("W_Gait")); +static const FName NAME__ALSCharacterAnimInstance__root(TEXT("root")); + + void UALSCharacterAnimInstance::NativeInitializeAnimation() { Super::NativeInitializeAnimation(); Character = Cast(TryGetPawnOwner()); + if (Character) + { + Character->OnJumpedDelegate.AddUniqueDynamic(this, &UALSCharacterAnimInstance::OnJumped); + } +} + +void UALSCharacterAnimInstance::NativeBeginPlay() +{ + // it seems to be that the player pawn components are not really initialized + // when the call to NativeInitializeAnimation() happens. + // This is the reason why it is tried here to get the ALS debug component. + if (APawn* Owner = TryGetPawnOwner()) + { + ALSDebugComponent = Owner->FindComponentByClass(); + } } void UALSCharacterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) @@ -25,18 +72,30 @@ void UALSCharacterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) if (!Character || DeltaSeconds == 0.0f) { - // Fix character looking right on editor - RotationMode = EALSRotationMode::VelocityDirection; - - // Don't run in editor return; } // Update rest of character information. Others are reflected into anim bp when they're set inside character class + CharacterInformation.MovementInputAmount = Character->GetMovementInputAmount(); + CharacterInformation.bHasMovementInput = Character->HasMovementInput(); + CharacterInformation.bIsMoving = Character->IsMoving(); + CharacterInformation.Acceleration = Character->GetAcceleration(); + CharacterInformation.AimYawRate = Character->GetAimYawRate(); + CharacterInformation.Speed = Character->GetSpeed(); CharacterInformation.Velocity = Character->GetCharacterMovement()->Velocity; CharacterInformation.MovementInput = Character->GetMovementInput(); CharacterInformation.AimingRotation = Character->GetAimingRotation(); CharacterInformation.CharacterActorRotation = Character->GetActorRotation(); + CharacterInformation.ViewMode = Character->GetViewMode(); + CharacterInformation.PrevMovementState = Character->GetPrevMovementState(); + LayerBlendingValues.OverlayOverrideState = Character->GetOverlayOverrideState(); + MovementState = Character->GetMovementState(); + MovementAction = Character->GetMovementAction(); + Stance = Character->GetStance(); + RotationMode = Character->GetRotationMode(); + Gait = Character->GetGait(); + OverlayState = Character->GetOverlayState(); + GroundedEntryState = Character->GetGroundedEntryState(); UpdateAimingValues(DeltaSeconds); UpdateLayerValues(); @@ -102,7 +161,7 @@ void UALSCharacterAnimInstance::NativeUpdateAnimation(float DeltaSeconds) void UALSCharacterAnimInstance::PlayTransition(const FALSDynamicMontageParams& Parameters) { - PlaySlotAnimationAsDynamicMontage(Parameters.Animation, FName(TEXT("Grounded Slot")), + PlaySlotAnimationAsDynamicMontage(Parameters.Animation, NAME_Grounded___Slot, Parameters.BlendInTime, Parameters.BlendOutTime, Parameters.PlayRate, 1, 0.0f, Parameters.StartTime); } @@ -148,12 +207,12 @@ bool UALSCharacterAnimInstance::CanTurnInPlace() const { return RotationMode.LookingDirection() && CharacterInformation.ViewMode == EALSViewMode::ThirdPerson && - GetCurveValue(FName(TEXT("Enable_Transition"))) >= 0.99f; + GetCurveValue(NAME_Enable_Transition) >= 0.99f; } bool UALSCharacterAnimInstance::CanDynamicTransition() const { - return GetCurveValue(FName(TEXT("Enable_Transition"))) >= 0.99f; + return GetCurveValue(NAME_Enable_Transition) >= 0.99f; } void UALSCharacterAnimInstance::PlayDynamicTransitionDelay() @@ -196,7 +255,7 @@ void UALSCharacterAnimInstance::UpdateAimingValues(float DeltaSeconds) if (!RotationMode.VelocityDirection()) { // Clamp the Aiming Pitch Angle to a range of 1 to 0 for use in the vertical aim sweeps. - AimingValues.AimSweepTime = FMath::GetMappedRangeValueClamped({-90.0f, 90.0f}, {1.0f, 0.0f}, + AimingValues.AimSweepTime = FMath::GetMappedRangeValueClamped({-90.0f, 90.0f}, {1.0f, 0.0f}, AimingValues.AimingAngle.Y); // Use the Aiming Yaw Angle divided by the number of spine+pelvis bones to get the amount of spine rotation @@ -211,7 +270,7 @@ void UALSCharacterAnimInstance::UpdateAimingValues(float DeltaSeconds) // This value is used in the aim offset behavior to make the character look toward the Movement Input. Delta = CharacterInformation.MovementInput.ToOrientationRotator() - CharacterInformation.CharacterActorRotation; Delta.Normalize(); - const float InterpTarget = FMath::GetMappedRangeValueClamped({-180.0f, 180.0f}, {0.0f, 1.0f}, Delta.Yaw); + const float InterpTarget = FMath::GetMappedRangeValueClamped({-180.0f, 180.0f}, {0.0f, 1.0f}, Delta.Yaw); AimingValues.InputYawOffsetTime = FMath::FInterpTo(AimingValues.InputYawOffsetTime, InterpTarget, DeltaSeconds, Config.InputYawOffsetInterpSpeed); @@ -220,39 +279,39 @@ void UALSCharacterAnimInstance::UpdateAimingValues(float DeltaSeconds) // Separate the Aiming Yaw Angle into 3 separate Yaw Times. These 3 values are used in the Aim Offset behavior // to improve the blending of the aim offset when rotating completely around the character. // This allows you to keep the aiming responsive but still smoothly blend from left to right or right to left. - AimingValues.LeftYawTime = FMath::GetMappedRangeValueClamped({0.0f, 180.0f}, {0.5f, 0.0f}, + AimingValues.LeftYawTime = FMath::GetMappedRangeValueClamped({0.0f, 180.0f}, {0.5f, 0.0f}, FMath::Abs(SmoothedAimingAngle.X)); - AimingValues.RightYawTime = FMath::GetMappedRangeValueClamped({0.0f, 180.0f}, {0.5f, 1.0f}, + AimingValues.RightYawTime = FMath::GetMappedRangeValueClamped({0.0f, 180.0f}, {0.5f, 1.0f}, FMath::Abs(SmoothedAimingAngle.X)); - AimingValues.ForwardYawTime = FMath::GetMappedRangeValueClamped({-180.0f, 180.0f}, {0.0f, 1.0f}, + AimingValues.ForwardYawTime = FMath::GetMappedRangeValueClamped({-180.0f, 180.0f}, {0.0f, 1.0f}, SmoothedAimingAngle.X); } void UALSCharacterAnimInstance::UpdateLayerValues() { // Get the Aim Offset weight by getting the opposite of the Aim Offset Mask. - LayerBlendingValues.EnableAimOffset = FMath::Lerp(1.0f, 0.0f, GetCurveValue(FName(TEXT("Mask_AimOffset")))); + LayerBlendingValues.EnableAimOffset = FMath::Lerp(1.0f, 0.0f, GetCurveValue(NAME_Mask_AimOffset)); // Set the Base Pose weights - LayerBlendingValues.BasePose_N = GetCurveValue(FName(TEXT("BasePose_N"))); - LayerBlendingValues.BasePose_CLF = GetCurveValue(FName(TEXT("BasePose_CLF"))); + LayerBlendingValues.BasePose_N = GetCurveValue(NAME_BasePose_N); + LayerBlendingValues.BasePose_CLF = GetCurveValue(NAME_BasePose_CLF); // Set the Additive amount weights for each body part - LayerBlendingValues.Spine_Add = GetCurveValue(FName(TEXT("Layering_Spine_Add"))); - LayerBlendingValues.Head_Add = GetCurveValue(FName(TEXT("Layering_Head_Add"))); - LayerBlendingValues.Arm_L_Add = GetCurveValue(FName(TEXT("Layering_Arm_L_Add"))); - LayerBlendingValues.Arm_R_Add = GetCurveValue(FName(TEXT("Layering_Arm_R_Add"))); + LayerBlendingValues.Spine_Add = GetCurveValue(NAME_Layering_Spine_Add); + LayerBlendingValues.Head_Add = GetCurveValue(NAME_Layering_Head_Add); + LayerBlendingValues.Arm_L_Add = GetCurveValue(NAME_Layering_Arm_L_Add); + LayerBlendingValues.Arm_R_Add = GetCurveValue(NAME_Layering_Arm_R_Add); // Set the Hand Override weights - LayerBlendingValues.Hand_R = GetCurveValue(FName(TEXT("Layering_Hand_R"))); - LayerBlendingValues.Hand_L = GetCurveValue(FName(TEXT("Layering_Hand_L"))); + LayerBlendingValues.Hand_R = GetCurveValue(NAME_Layering_Hand_R); + LayerBlendingValues.Hand_L = GetCurveValue(NAME_Layering_Hand_L); // Blend and set the Hand IK weights to ensure they only are weighted if allowed by the Arm layers. - LayerBlendingValues.EnableHandIK_L = FMath::Lerp(0.0f, GetCurveValue(FName(TEXT("Enable_HandIK_L"))), - GetCurveValue(FName(TEXT("Layering_Arm_L")))); - LayerBlendingValues.EnableHandIK_R = FMath::Lerp(0.0f, GetCurveValue(FName(TEXT("Enable_HandIK_R"))), - GetCurveValue(FName(TEXT("Layering_Arm_R")))); + LayerBlendingValues.EnableHandIK_L = FMath::Lerp(0.0f, GetCurveValue(NAME_Enable_HandIK_L), + GetCurveValue(NAME_Layering_Arm_L)); + LayerBlendingValues.EnableHandIK_R = FMath::Lerp(0.0f, GetCurveValue(NAME_Enable_HandIK_R), + GetCurveValue(NAME_Layering_Arm_R)); // Set whether the arms should blend in mesh space or local space. // The Mesh space weight will always be 1 unless the Local Space (LS) curve is fully weighted. - LayerBlendingValues.Arm_L_LS = GetCurveValue(FName(TEXT("Layering_Arm_L_LS"))); + LayerBlendingValues.Arm_L_LS = GetCurveValue(NAME_Layering_Arm_L_LS); LayerBlendingValues.Arm_L_MS = static_cast(1 - FMath::FloorToInt(LayerBlendingValues.Arm_L_LS)); - LayerBlendingValues.Arm_R_LS = GetCurveValue(FName(TEXT("Layering_Arm_R_LS"))); + LayerBlendingValues.Arm_R_LS = GetCurveValue(NAME_Layering_Arm_R_LS); LayerBlendingValues.Arm_R_MS = static_cast(1 - FMath::FloorToInt(LayerBlendingValues.Arm_R_LS)); } @@ -262,10 +321,10 @@ void UALSCharacterAnimInstance::UpdateFootIK(float DeltaSeconds) FVector FootOffsetRTarget = FVector::ZeroVector; // Update Foot Locking values. - SetFootLocking(DeltaSeconds, FName(TEXT("Enable_FootIK_L")), FName(TEXT("FootLock_L")), + SetFootLocking(DeltaSeconds, NAME_Enable_FootIK_L, NAME_FootLock_L, IkFootL_BoneName, FootIKValues.FootLock_L_Alpha, FootIKValues.UseFootLockCurve_L, FootIKValues.FootLock_L_Location, FootIKValues.FootLock_L_Rotation); - SetFootLocking(DeltaSeconds, FName(TEXT("Enable_FootIK_R")), FName(TEXT("FootLock_R")), + SetFootLocking(DeltaSeconds, NAME_Enable_FootIK_R, NAME_FootLock_R, IkFootR_BoneName, FootIKValues.FootLock_R_Alpha, FootIKValues.UseFootLockCurve_R, FootIKValues.FootLock_R_Location, FootIKValues.FootLock_R_Rotation); @@ -278,10 +337,10 @@ void UALSCharacterAnimInstance::UpdateFootIK(float DeltaSeconds) else if (!MovementState.Ragdoll()) { // Update all Foot Lock and Foot Offset values when not In Air - SetFootOffsets(DeltaSeconds, FName(TEXT("Enable_FootIK_L")), IkFootL_BoneName, FName(TEXT("root")), + SetFootOffsets(DeltaSeconds, NAME_Enable_FootIK_L, IkFootL_BoneName, NAME__ALSCharacterAnimInstance__root, FootOffsetLTarget, FootIKValues.FootOffset_L_Location, FootIKValues.FootOffset_L_Rotation); - SetFootOffsets(DeltaSeconds, FName(TEXT("Enable_FootIK_R")), IkFootR_BoneName, FName(TEXT("root")), + SetFootOffsets(DeltaSeconds, NAME_Enable_FootIK_R, IkFootR_BoneName, NAME__ALSCharacterAnimInstance__root, FootOffsetRTarget, FootIKValues.FootOffset_R_Location, FootIKValues.FootOffset_R_Rotation); SetPelvisIKOffset(DeltaSeconds, FootOffsetLTarget, FootOffsetRTarget); @@ -302,7 +361,7 @@ void UALSCharacterAnimInstance::SetFootLocking(float DeltaSeconds, FName EnableF if (UseFootLockCurve) { - UseFootLockCurve = FMath::Abs(GetCurveValue(FName(TEXT("RotationAmount")))) <= 0.001f || + UseFootLockCurve = FMath::Abs(GetCurveValue(NAME__ALSCharacterAnimInstance__RotationAmount)) <= 0.001f || Character->GetLocalRole() != ROLE_AutonomousProxy; FootLockCurveVal = GetCurveValue(FootLockCurve) * (1.f / GetSkelMeshComponent()->AnimUpdateRateParams->UpdateRate); } @@ -368,7 +427,7 @@ void UALSCharacterAnimInstance::SetPelvisIKOffset(float DeltaSeconds, FVector Fo { // Calculate the Pelvis Alpha by finding the average Foot IK weight. If the alpha is 0, clear the offset. FootIKValues.PelvisAlpha = - (GetCurveValue(FName(TEXT("Enable_FootIK_L"))) + GetCurveValue(FName(TEXT("Enable_FootIK_R")))) / 2.0f; + (GetCurveValue(NAME_Enable_FootIK_L) + GetCurveValue(NAME_Enable_FootIK_R)) / 2.0f; if (FootIKValues.PelvisAlpha > 0.0f) { @@ -424,11 +483,28 @@ void UALSCharacterAnimInstance::SetFootOffsets(float DeltaSeconds, FName EnableF FCollisionQueryParams Params; Params.AddIgnoredActor(Character); + const FVector TraceStart = IKFootFloorLoc + FVector(0.0, 0.0, Config.IK_TraceDistanceAboveFoot); + const FVector TraceEnd = IKFootFloorLoc - FVector(0.0, 0.0, Config.IK_TraceDistanceBelowFoot); + FHitResult HitResult; - World->LineTraceSingleByChannel(HitResult, - IKFootFloorLoc + FVector(0.0, 0.0, Config.IK_TraceDistanceAboveFoot), - IKFootFloorLoc - FVector(0.0, 0.0, Config.IK_TraceDistanceBelowFoot), - ECC_Visibility, Params); + const bool bHit = World->LineTraceSingleByChannel(HitResult, + TraceStart, + TraceEnd, + ECC_Visibility, Params); + + if (ALSDebugComponent && ALSDebugComponent->GetShowTraces()) + { + UALSDebugComponent::DrawDebugLineTraceSingle( + World, + TraceStart, + TraceEnd, + EDrawDebugTrace::Type::ForOneFrame, + bHit, + HitResult, + FLinearColor::Red, + FLinearColor::Green, + 5.0f); + } FRotator TargetRotOffset = FRotator::ZeroRotator; if (Character->GetCharacterMovement()->IsWalkable(HitResult)) @@ -437,7 +513,7 @@ void UALSCharacterAnimInstance::SetFootOffsets(float DeltaSeconds, FName EnableF FVector ImpactNormal = HitResult.ImpactNormal; // Step 1.1: Find the difference in location from the Impact point and the expected (flat) floor location. - // These values are offset by the nomrmal multiplied by the + // These values are offset by the normal multiplied by the // foot height to get better behavior on angled surfaces. CurLocationTarget = (ImpactPoint + ImpactNormal * Config.FootHeight) - (IKFootFloorLoc + FVector(0, 0, Config.FootHeight)); @@ -466,7 +542,7 @@ void UALSCharacterAnimInstance::RotateInPlaceCheck() // This makes the character rotate faster when moving the camera faster. if (Grounded.bRotateL || Grounded.bRotateR) { - Grounded.RotateRate = FMath::GetMappedRangeValueClamped( + Grounded.RotateRate = FMath::GetMappedRangeValueClamped( {RotateInPlace.AimYawRateMinRange, RotateInPlace.AimYawRateMaxRange}, {RotateInPlace.MinPlayRate, RotateInPlace.MaxPlayRate}, CharacterInformation.AimYawRate); @@ -477,7 +553,7 @@ void UALSCharacterAnimInstance::TurnInPlaceCheck(float DeltaSeconds) { // Step 1: Check if Aiming angle is outside of the Turn Check Min Angle, and if the Aim Yaw Rate is below the Aim Yaw Rate Limit. // If so, begin counting the Elapsed Delay Time. If not, reset the Elapsed Delay Time. - // This ensures the conditions remain true for a sustained peroid of time before turning in place. + // This ensures the conditions remain true for a sustained period of time before turning in place. if (FMath::Abs(AimingValues.AimingAngle.X) <= TurnInPlaceValues.TurnCheckMinAngle || CharacterInformation.AimYawRate >= TurnInPlaceValues.AimYawRateLimit) { @@ -486,7 +562,7 @@ void UALSCharacterAnimInstance::TurnInPlaceCheck(float DeltaSeconds) } TurnInPlaceValues.ElapsedDelayTime += DeltaSeconds; - const float ClampedAimAngle = FMath::GetMappedRangeValueClamped({TurnInPlaceValues.TurnCheckMinAngle, 180.0f}, + const float ClampedAimAngle = FMath::GetMappedRangeValueClamped({TurnInPlaceValues.TurnCheckMinAngle, 180.0f}, { TurnInPlaceValues.MinAngleDelay, TurnInPlaceValues.MaxAngleDelay @@ -511,7 +587,7 @@ void UALSCharacterAnimInstance::DynamicTransitionCheck() // Because only the IK_Foot bone can be locked, the separate virtual bone allows the system to know its desired location when locked. FTransform SocketTransformA = GetOwningComponent()->GetSocketTransform(IkFootL_BoneName, RTS_Component); FTransform SocketTransformB = GetOwningComponent()->GetSocketTransform( - FName(TEXT("VB foot_target_l")), RTS_Component); + NAME_VB___foot_target_l, RTS_Component); float Distance = (SocketTransformB.GetLocation() - SocketTransformA.GetLocation()).Size(); if (Distance > Config.DynamicTransitionThreshold) { @@ -525,7 +601,7 @@ void UALSCharacterAnimInstance::DynamicTransitionCheck() } SocketTransformA = GetOwningComponent()->GetSocketTransform(IkFootR_BoneName, RTS_Component); - SocketTransformB = GetOwningComponent()->GetSocketTransform(FName(TEXT("VB foot_target_r")), RTS_Component); + SocketTransformB = GetOwningComponent()->GetSocketTransform(NAME_VB___foot_target_r, RTS_Component); Distance = (SocketTransformB.GetLocation() - SocketTransformA.GetLocation()).Size(); if (Distance > Config.DynamicTransitionThreshold) { @@ -574,7 +650,7 @@ void UALSCharacterAnimInstance::UpdateRotationValues() // Set the Movement Direction MovementDirection = CalculateMovementDirection(); - // Set the Yaw Offsets. These values influence the "YawOffset" curve in the animgraph and are used to offset + // Set the Yaw Offsets. These values influence the "YawOffset" curve in the AnimGraph and are used to offset // the characters rotation for more natural movement. The curves allow for fine control over how the offset // behaves for each movement direction. FRotator Delta = CharacterInformation.Velocity.ToOrientationRotator() - CharacterInformation.AimingRotation; @@ -605,8 +681,8 @@ void UALSCharacterAnimInstance::UpdateInAirValues(float DeltaSeconds) void UALSCharacterAnimInstance::UpdateRagdollValues() { // Scale the Flail Rate by the velocity length. The faster the ragdoll moves, the faster the character will flail. - const float VelocityLength = GetOwningComponent()->GetPhysicsLinearVelocity(FName(TEXT("root"))).Size(); - FlailRate = FMath::GetMappedRangeValueClamped({0.0f, 1000.0f}, {0.0f, 1.0f}, VelocityLength); + const float VelocityLength = GetOwningComponent()->GetPhysicsLinearVelocity(NAME__ALSCharacterAnimInstance__root).Size(); + FlailRate = FMath::GetMappedRangeValueClamped({0.0f, 1000.0f}, {0.0f, 1.0f}, VelocityLength); } float UALSCharacterAnimInstance::GetAnimCurveClamped(const FName& Name, float Bias, float ClampMin, @@ -659,12 +735,12 @@ float UALSCharacterAnimInstance::CalculateStrideBlend() const // the movement speed, preventing the character from needing to play a half walk+half run blend. // The curves are used to map the stride amount to the speed for maximum control. const float CurveTime = CharacterInformation.Speed / GetOwningComponent()->GetComponentScale().Z; - const float ClampedGait = GetAnimCurveClamped(FName(TEXT("W_Gait")), -1.0, 0.0f, 1.0f); + const float ClampedGait = GetAnimCurveClamped(NAME_W_Gait, -1.0, 0.0f, 1.0f); const float LerpedStrideBlend = FMath::Lerp(StrideBlend_N_Walk->GetFloatValue(CurveTime), StrideBlend_N_Run->GetFloatValue(CurveTime), ClampedGait); return FMath::Lerp(LerpedStrideBlend, StrideBlend_C_Walk->GetFloatValue(CharacterInformation.Speed), - GetCurveValue(FName(TEXT("BasePose_CLF")))); + GetCurveValue(NAME_BasePose_CLF)); } float UALSCharacterAnimInstance::CalculateWalkRunBlend() const @@ -681,10 +757,10 @@ float UALSCharacterAnimInstance::CalculateStandingPlayRate() const // The value is also divided by the Stride Blend and the mesh scale so that the play rate increases as the stride or scale gets smaller const float LerpedSpeed = FMath::Lerp(CharacterInformation.Speed / Config.AnimatedWalkSpeed, CharacterInformation.Speed / Config.AnimatedRunSpeed, - GetAnimCurveClamped(FName(TEXT("W_Gait")), -1.0f, 0.0f, 1.0f)); + GetAnimCurveClamped(NAME_W_Gait, -1.0f, 0.0f, 1.0f)); const float SprintAffectedSpeed = FMath::Lerp(LerpedSpeed, CharacterInformation.Speed / Config.AnimatedSprintSpeed, - GetAnimCurveClamped(FName(TEXT("W_Gait")), -2.0f, 0.0f, 1.0f)); + GetAnimCurveClamped(NAME_W_Gait, -2.0f, 0.0f, 1.0f)); return FMath::Clamp((SprintAffectedSpeed / Grounded.StrideBlend) / GetOwningComponent()->GetComponentScale().Z, 0.0f, 3.0f); @@ -692,7 +768,7 @@ float UALSCharacterAnimInstance::CalculateStandingPlayRate() const float UALSCharacterAnimInstance::CalculateDiagonalScaleAmount() const { - // Calculate the Diagnal Scale Amount. This value is used to scale the Foot IK Root bone to make the Foot IK bones + // Calculate the Diagonal Scale Amount. This value is used to scale the Foot IK Root bone to make the Foot IK bones // cover more distance on the diagonal blends. Without scaling, the feet would not move far enough on the diagonal // direction due to the linear translational blending of the IK bones. The curve is used to easily map the value. return DiagonalScaleAmountCurve->GetFloatValue(FMath::Abs(VelocityBlend.F + VelocityBlend.B)); @@ -701,7 +777,7 @@ float UALSCharacterAnimInstance::CalculateDiagonalScaleAmount() const float UALSCharacterAnimInstance::CalculateCrouchingPlayRate() const { // Calculate the Crouching Play Rate by dividing the Character's speed by the Animated Speed. - // This value needs to be separate from the standing play rate to improve the blend from crocuh to stand while in motion. + // This value needs to be separate from the standing play rate to improve the blend from crouch to stand while in motion. return FMath::Clamp( CharacterInformation.Speed / Config.AnimatedCrouchSpeed / Grounded.StrideBlend / GetOwningComponent()-> GetComponentScale().Z, @@ -712,7 +788,7 @@ float UALSCharacterAnimInstance::CalculateLandPrediction() const { // Calculate the land prediction weight by tracing in the velocity direction to find a walkable surface the character // is falling toward, and getting the 'Time' (range of 0-1, 1 being maximum, 0 being about to land) till impact. - // The Land Prediction Curve is used to control how the time affects the final weight for a smooth blend. + // The Land Prediction Curve is used to control how the time affects the final weight for a smooth blend. if (InAir.FallSpeed >= -200.0f) { return 0.0f; @@ -725,7 +801,7 @@ float UALSCharacterAnimInstance::CalculateLandPrediction() const VelocityClamped.Z = FMath::Clamp(VelocityZ, -4000.0f, -200.0f); VelocityClamped.Normalize(); - const FVector TraceLength = VelocityClamped * FMath::GetMappedRangeValueClamped( + const FVector TraceLength = VelocityClamped * FMath::GetMappedRangeValueClamped( {0.0f, -4000.0f}, {50.0f, 2000.0f}, VelocityZ); UWorld* World = GetWorld(); @@ -735,16 +811,29 @@ float UALSCharacterAnimInstance::CalculateLandPrediction() const Params.AddIgnoredActor(Character); FHitResult HitResult; + const FCollisionShape CapsuleCollisionShape = FCollisionShape::MakeCapsule(CapsuleComp->GetUnscaledCapsuleRadius(), + CapsuleComp->GetUnscaledCapsuleHalfHeight()); + const bool bHit = World->SweepSingleByChannel(HitResult, CapsuleWorldLoc, CapsuleWorldLoc + TraceLength, FQuat::Identity, + ECC_Visibility, CapsuleCollisionShape, Params); - World->SweepSingleByChannel(HitResult, CapsuleWorldLoc, CapsuleWorldLoc + TraceLength, FQuat::Identity, - ECC_Visibility, - FCollisionShape::MakeCapsule(CapsuleComp->GetUnscaledCapsuleRadius(), - CapsuleComp->GetUnscaledCapsuleHalfHeight()), Params); + if (ALSDebugComponent && ALSDebugComponent->GetShowTraces()) + { + UALSDebugComponent::DrawDebugCapsuleTraceSingle(World, + CapsuleWorldLoc, + CapsuleWorldLoc + TraceLength, + CapsuleCollisionShape, + EDrawDebugTrace::Type::ForOneFrame, + bHit, + HitResult, + FLinearColor::Red, + FLinearColor::Green, + 5.0f); + } if (Character->GetCharacterMovement()->IsWalkable(HitResult)) { return FMath::Lerp(LandPredictionCurve->GetFloatValue(HitResult.Time), 0.0f, - GetCurveValue(FName(TEXT("Mask_LandPrediction")))); + GetCurveValue(NAME_Mask_LandPrediction)); } return 0.0f; @@ -768,7 +857,7 @@ FALSLeanAmount UALSCharacterAnimInstance::CalculateAirLeanAmount() const EALSMovementDirection UALSCharacterAnimInstance::CalculateMovementDirection() const { // Calculate the Movement Direction. This value represents the direction the character is moving relative to the camera - // during the Looking Cirection / Aiming rotation modes, and is used in the Cycle Blending Anim Layers to blend to the + // during the Looking Direction / Aiming rotation modes, and is used in the Cycle Blending Anim Layers to blend to the // appropriate directional states. if (Gait.Sprinting() || RotationMode.VelocityDirection()) { @@ -788,9 +877,8 @@ void UALSCharacterAnimInstance::TurnInPlace(FRotator TargetRotation, float PlayR Delta.Normalize(); const float TurnAngle = Delta.Yaw; - FALSTurnInPlaceAsset TargetTurnAsset; // Step 2: Choose Turn Asset based on the Turn Angle and Stance - + FALSTurnInPlaceAsset TargetTurnAsset; if (Stance.Standing()) { if (FMath::Abs(TurnAngle) < TurnInPlaceValues.Turn180Threshold) @@ -830,7 +918,7 @@ void UALSCharacterAnimInstance::TurnInPlace(FRotator TargetRotation, float PlayR PlaySlotAnimationAsDynamicMontage(TargetTurnAsset.Animation, TargetTurnAsset.SlotName, 0.2f, 0.2f, TargetTurnAsset.PlayRate * PlayRateScale, 1, 0.0f, StartTime); - // Step 4: Scale the rotation amount (gets scaled in animgraph) to compensate for turn angle (If Allowed) and play rate. + // Step 4: Scale the rotation amount (gets scaled in AnimGraph) to compensate for turn angle (If Allowed) and play rate. if (TargetTurnAsset.ScaleTurnAngle) { Grounded.RotationScale = (TurnAngle / TargetTurnAsset.AnimatedAngle) * TargetTurnAsset.PlayRate * PlayRateScale; @@ -844,19 +932,15 @@ void UALSCharacterAnimInstance::TurnInPlace(FRotator TargetRotation, float PlayR void UALSCharacterAnimInstance::OnJumped() { InAir.bJumped = true; - InAir.JumpPlayRate = FMath::GetMappedRangeValueClamped({0.0f, 600.0f}, {1.2f, 1.5f}, CharacterInformation.Speed); + InAir.JumpPlayRate = FMath::GetMappedRangeValueClamped({0.0f, 600.0f}, {1.2f, 1.5f}, CharacterInformation.Speed); - UWorld* World = GetWorld(); - check(World); - World->GetTimerManager().SetTimer(OnJumpedTimer, this, + GetWorld()->GetTimerManager().SetTimer(OnJumpedTimer, this, &UALSCharacterAnimInstance::OnJumpedDelay, 0.1f, false); } void UALSCharacterAnimInstance::OnPivot() { Grounded.bPivot = CharacterInformation.Speed < Config.TriggerPivotSpeedLimit; - UWorld* World = GetWorld(); - check(World); - World->GetTimerManager().SetTimer(OnPivotTimer, this, + GetWorld()->GetTimerManager().SetTimer(OnPivotTimer, this, &UALSCharacterAnimInstance::OnPivotDelay, 0.1f, false); } diff --git a/Source/ALSV4_CPP/Private/Character/Animation/ALSPlayerCameraBehavior.cpp b/Source/ALSV4_CPP/Private/Character/Animation/ALSPlayerCameraBehavior.cpp index 9009c5352..c9d50eac0 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/ALSPlayerCameraBehavior.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/ALSPlayerCameraBehavior.cpp @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/Animation/ALSPlayerCameraBehavior.h" diff --git a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyCameraShake.cpp b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyCameraShake.cpp index e5b8dc3ef..3bbc79048 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyCameraShake.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyCameraShake.cpp @@ -1,16 +1,18 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/Animation/Notify/ALSAnimNotifyCameraShake.h" +#include "Components/SkeletalMeshComponent.h" -void UALSAnimNotifyCameraShake::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) +#include "GameFramework/Pawn.h" +#include "GameFramework/PlayerController.h" + +void UALSAnimNotifyCameraShake::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) { + Super::Notify(MeshComp, Animation, EventReference); + APawn* OwnerPawn = Cast(MeshComp->GetOwner()); if (OwnerPawn) { diff --git a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyFootstep.cpp b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyFootstep.cpp index 0acd6ffcb..38117b410 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyFootstep.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyFootstep.cpp @@ -1,28 +1,37 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/Animation/Notify/ALSAnimNotifyFootstep.h" +#include "Animation/AnimInstance.h" #include "Components/AudioComponent.h" +#include "Components/SkeletalMeshComponent.h" + #include "Engine/DataTable.h" +#include "Kismet/KismetSystemLibrary.h" #include "Library/ALSCharacterStructLibrary.h" #include "PhysicalMaterials/PhysicalMaterial.h" #include "NiagaraSystem.h" #include "NiagaraFunctionLibrary.h" +#include "Sound/SoundBase.h" + + +const FName NAME_Mask_FootstepSound(TEXT("Mask_FootstepSound")); + +FName UALSAnimNotifyFootstep::NAME_FootstepType(TEXT("FootstepType")); +FName UALSAnimNotifyFootstep::NAME_Foot_R(TEXT("Foot_R")); -void UALSAnimNotifyFootstep::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) +void UALSAnimNotifyFootstep::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) { + Super::Notify(MeshComp, Animation, EventReference); + if (!MeshComp) { return; } - + AActor* MeshOwner = MeshComp->GetOwner(); if (!MeshOwner) { @@ -39,11 +48,9 @@ void UALSAnimNotifyFootstep::Notify(USkeletalMeshComponent* MeshComp, UAnimSeque const FVector TraceEnd = FootLocation - MeshOwner->GetActorUpVector() * TraceLength; FHitResult Hit; - TArray ActorsToIgnore; - ActorsToIgnore.Add(MeshOwner); - ActorsToIgnore.Append(MeshOwner->Children); - if (UKismetSystemLibrary::LineTraceSingle(World, FootLocation, TraceEnd, TraceChannel, true, ActorsToIgnore, - DrawDebugType, Hit, true)) + + if (UKismetSystemLibrary::LineTraceSingle(MeshOwner /*used by bIgnoreSelf*/, FootLocation, TraceEnd, TraceChannel, true /*bTraceComplex*/, MeshOwner->Children, + DrawDebugType, Hit, true /*bIgnoreSelf*/)) { if (!Hit.PhysMaterial.Get()) { @@ -52,7 +59,11 @@ void UALSAnimNotifyFootstep::Notify(USkeletalMeshComponent* MeshComp, UAnimSeque const EPhysicalSurface SurfaceType = Hit.PhysMaterial.Get()->SurfaceType; - TArray HitFXRows; + check(IsInGameThread()); + checkNoRecursion(); + static TArray HitFXRows; + HitFXRows.Reset(); + HitDataTable->GetAllRows(FString(), HitFXRows); FALSHitFX* HitFX = nullptr; @@ -80,7 +91,7 @@ void UALSAnimNotifyFootstep::Notify(USkeletalMeshComponent* MeshComp, UAnimSeque UAudioComponent* SpawnedSound = nullptr; const float MaskCurveValue = MeshComp->GetAnimInstance()->GetCurveValue( - FName(TEXT("Mask_FootstepSound"))); + NAME_Mask_FootstepSound); const float FinalVolMult = bOverrideMaskCurve ? VolumeMultiplier : VolumeMultiplier * (1.0f - MaskCurveValue); diff --git a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.cpp b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.cpp index 2d2756f01..684a8b413 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.cpp @@ -1,21 +1,20 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h" +#include "Character/ALSBaseCharacter.h" #include "Character/Animation/ALSCharacterAnimInstance.h" -void UALSAnimNotifyGroundedEntryState::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) +void UALSAnimNotifyGroundedEntryState::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) { - UALSCharacterAnimInstance* AnimIns = Cast(MeshComp->GetAnimInstance()); - if (AnimIns) + Super::Notify(MeshComp, Animation, EventReference); + + AALSBaseCharacter* Character = Cast(MeshComp->GetOwner()); + if (Character) { - AnimIns->SetGroundedEntryState(GroundedEntryState); + Character->SetGroundedEntryState(GroundedEntryState); } } diff --git a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.cpp b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.cpp index 725cb1656..089d9b6c2 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.cpp @@ -1,18 +1,18 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h" +#include "Components/SkeletalMeshComponent.h" +#include "Animation/AnimInstance.h" #include "Character/ALSBaseCharacter.h" void UALSNotifyStateEarlyBlendOut::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, - float FrameDeltaTime) + float FrameDeltaTime, const FAnimNotifyEventReference& EventReference) { + Super::NotifyTick(MeshComp, Animation, FrameDeltaTime, EventReference); + if (!MeshComp || !MeshComp->GetAnimInstance()) { return; @@ -20,7 +20,7 @@ void UALSNotifyStateEarlyBlendOut::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimInstance* AnimInstance = MeshComp->GetAnimInstance(); AALSBaseCharacter* OwnerCharacter = Cast(MeshComp->GetOwner()); - if (!OwnerCharacter) + if (!OwnerCharacter || !AnimInstance) { return; } diff --git a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateMovementAction.cpp b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateMovementAction.cpp index b1ce68eec..d21ccec2b 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateMovementAction.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateMovementAction.cpp @@ -1,18 +1,18 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/Animation/Notify/ALSNotifyStateMovementAction.h" #include "Character/ALSBaseCharacter.h" +#include "Components/SkeletalMeshComponent.h" + void UALSNotifyStateMovementAction::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, - float TotalDuration) + float TotalDuration, const FAnimNotifyEventReference& EventReference) { + Super::NotifyBegin(MeshComp, Animation, TotalDuration, EventReference); + AALSBaseCharacter* BaseCharacter = Cast(MeshComp->GetOwner()); if (BaseCharacter) { @@ -20,8 +20,11 @@ void UALSNotifyStateMovementAction::NotifyBegin(USkeletalMeshComponent* MeshComp } } -void UALSNotifyStateMovementAction::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) +void UALSNotifyStateMovementAction::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, + const FAnimNotifyEventReference& EventReference) { + Super::NotifyEnd(MeshComp, Animation, EventReference); + AALSBaseCharacter* BaseCharacter = Cast(MeshComp->GetOwner()); if (BaseCharacter && BaseCharacter->GetMovementAction() == MovementAction) { diff --git a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateOverlayOverride.cpp b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateOverlayOverride.cpp index 7e6d2f587..5152ba3cd 100644 --- a/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateOverlayOverride.cpp +++ b/Source/ALSV4_CPP/Private/Character/Animation/Notify/ALSNotifyStateOverlayOverride.cpp @@ -1,31 +1,32 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Character/Animation/Notify/ALSNotifyStateOverlayOverride.h" +#include "Character/ALSBaseCharacter.h" #include "Character/Animation/ALSCharacterAnimInstance.h" void UALSNotifyStateOverlayOverride::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, - float TotalDuration) + float TotalDuration, const FAnimNotifyEventReference& EventReference) { - UALSCharacterAnimInstance* AnimInst = Cast(MeshComp->GetAnimInstance()); - if (AnimInst) + Super::NotifyBegin(MeshComp, Animation, TotalDuration, EventReference); + + AALSBaseCharacter* Character = Cast(MeshComp->GetOwner()); + if (Character) { - AnimInst->SetOverlayOverrideState(OverlayOverrideState); + Character->SetOverlayOverrideState(OverlayOverrideState); } } -void UALSNotifyStateOverlayOverride::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) +void UALSNotifyStateOverlayOverride::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) { - UALSCharacterAnimInstance* AnimInst = Cast(MeshComp->GetAnimInstance()); - if (AnimInst) + Super::NotifyEnd(MeshComp, Animation, EventReference); + + AALSBaseCharacter* Character = Cast(MeshComp->GetOwner()); + if (Character) { - AnimInst->SetOverlayOverrideState(0); + Character->SetOverlayOverrideState(0); } } diff --git a/Source/ALSV4_CPP/Private/Components/ALSDebugComponent.cpp b/Source/ALSV4_CPP/Private/Components/ALSDebugComponent.cpp index ba650ecee..921d38d49 100644 --- a/Source/ALSV4_CPP/Private/Components/ALSDebugComponent.cpp +++ b/Source/ALSV4_CPP/Private/Components/ALSDebugComponent.cpp @@ -1,23 +1,19 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Components/ALSDebugComponent.h" #include "Character/ALSBaseCharacter.h" -#include "Character/ALSCharacter.h" #include "Character/ALSPlayerCameraManager.h" #include "Character/Animation/ALSPlayerCameraBehavior.h" #include "Kismet/GameplayStatics.h" +#include "DrawDebugHelpers.h" -bool UALSDebugComponent::bDebugView; -bool UALSDebugComponent::bShowTraces; -bool UALSDebugComponent::bShowDebugShapes; -bool UALSDebugComponent::bShowLayerColors; +bool UALSDebugComponent::bDebugView = false; +bool UALSDebugComponent::bShowTraces = false; +bool UALSDebugComponent::bShowDebugShapes = false; +bool UALSDebugComponent::bShowLayerColors = false; UALSDebugComponent::UALSDebugComponent() { @@ -82,12 +78,45 @@ void UALSDebugComponent::OnComponentDestroyed(bool bDestroyingHierarchy) bShowLayerColors = false; } +void UALSDebugComponent::FocusedDebugCharacterCycle(bool bValue) +{ + // Refresh list, so we can also debug runtime spawned characters & remove despawned characters back + DetectDebuggableCharactersInWorld(); + + if (FocusedDebugCharacterIndex == INDEX_NONE) + { + // Return here as no AALSBaseCharacter where found during call of BeginPlay. + // Moreover, for safety set also no focused debug character. + DebugFocusCharacter = nullptr; + return; + } + + if (bValue) + { + FocusedDebugCharacterIndex++; + if (FocusedDebugCharacterIndex >= AvailableDebugCharacters.Num()) + { + FocusedDebugCharacterIndex = 0; + } + } + else + { + FocusedDebugCharacterIndex--; + if (FocusedDebugCharacterIndex < 0) + { + FocusedDebugCharacterIndex = AvailableDebugCharacters.Num() - 1; + } + } + + DebugFocusCharacter = AvailableDebugCharacters[FocusedDebugCharacterIndex]; +} + void UALSDebugComponent::BeginPlay() { Super::BeginPlay(); - - OwnerCharacter = Cast(GetOwner()); + OwnerCharacter = Cast(GetOwner()); + DebugFocusCharacter = OwnerCharacter; if (OwnerCharacter) { SetDynamicMaterials(); @@ -95,6 +124,33 @@ void UALSDebugComponent::BeginPlay() } } +void UALSDebugComponent::DetectDebuggableCharactersInWorld() +{ + // Get all ALSBaseCharacter's, which are currently present to show them later in the ALS HUD for debugging purposes. + TArray AlsBaseCharacters; + UGameplayStatics::GetAllActorsOfClass(GetWorld(), AALSBaseCharacter::StaticClass(), AlsBaseCharacters); + + AvailableDebugCharacters.Empty(); + if (AlsBaseCharacters.Num() > 0) + { + AvailableDebugCharacters.Reserve(AlsBaseCharacters.Num()); + for (AActor* Character : AlsBaseCharacters) + { + if (AALSBaseCharacter* AlsBaseCharacter = Cast(Character)) + { + AvailableDebugCharacters.Add(AlsBaseCharacter); + } + } + + FocusedDebugCharacterIndex = AvailableDebugCharacters.Find(DebugFocusCharacter); + if (FocusedDebugCharacterIndex == INDEX_NONE && AvailableDebugCharacters.Num() > 0) + { // seems to be that this component was not attached to and AALSBaseCharacter, + // therefore the index will be set to the first element in the array. + FocusedDebugCharacterIndex = 0; + } + } +} + void UALSDebugComponent::ToggleGlobalTimeDilationLocal(float TimeDilation) { if (UKismetSystemLibrary::IsStandalone(this)) @@ -126,6 +182,14 @@ void UALSDebugComponent::ToggleDebugView() } } +void UALSDebugComponent::OpenOverlayMenu_Implementation(bool bValue) +{ +} + +void UALSDebugComponent::OverlayMenuCycle_Implementation(bool bValue) +{ +} + void UALSDebugComponent::ToggleDebugMesh() { if (bDebugMeshVisible) @@ -134,8 +198,128 @@ void UALSDebugComponent::ToggleDebugMesh() } else { - DefaultSkeletalMesh = OwnerCharacter->GetMesh()->SkeletalMesh; + DefaultSkeletalMesh = OwnerCharacter->GetMesh()->GetSkeletalMeshAsset(); OwnerCharacter->SetVisibleMesh(DebugSkeletalMesh); } bDebugMeshVisible = !bDebugMeshVisible; } + + +/** Util for drawing result of single line trace */ +void UALSDebugComponent::DrawDebugLineTraceSingle(const UWorld* World, + const FVector& Start, + const FVector& End, + EDrawDebugTrace::Type + DrawDebugType, + bool bHit, + const FHitResult& OutHit, + FLinearColor TraceColor, + FLinearColor TraceHitColor, + float DrawTime) +{ + if (DrawDebugType != EDrawDebugTrace::None) + { + bool bPersistent = DrawDebugType == EDrawDebugTrace::Persistent; + float LifeTime = (DrawDebugType == EDrawDebugTrace::ForDuration) ? DrawTime : 0.f; + + if (bHit && OutHit.bBlockingHit) + { + // Red up to the blocking hit, green thereafter + DrawDebugLine(World, Start, OutHit.ImpactPoint, TraceColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugLine(World, OutHit.ImpactPoint, End, TraceHitColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugPoint(World, OutHit.ImpactPoint, 16.0f, TraceColor.ToFColor(true), bPersistent, LifeTime); + } + else + { + // no hit means all red + DrawDebugLine(World, Start, End, TraceColor.ToFColor(true), bPersistent, LifeTime); + } + } +} + +void UALSDebugComponent::DrawDebugCapsuleTraceSingle(const UWorld* World, + const FVector& Start, + const FVector& End, + const FCollisionShape& CollisionShape, + EDrawDebugTrace::Type DrawDebugType, + bool bHit, + const FHitResult& OutHit, + FLinearColor TraceColor, + FLinearColor TraceHitColor, + float DrawTime) +{ + if (DrawDebugType != EDrawDebugTrace::None) + { + bool bPersistent = DrawDebugType == EDrawDebugTrace::Persistent; + float LifeTime = (DrawDebugType == EDrawDebugTrace::ForDuration) ? DrawTime : 0.f; + + if (bHit && OutHit.bBlockingHit) + { + // Red up to the blocking hit, green thereafter + DrawDebugCapsule(World, Start, CollisionShape.GetCapsuleHalfHeight(), CollisionShape.GetCapsuleRadius(), FQuat::Identity, TraceColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugCapsule(World, OutHit.Location, CollisionShape.GetCapsuleHalfHeight(), CollisionShape.GetCapsuleRadius(), FQuat::Identity, TraceColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugLine(World, Start, OutHit.Location, TraceColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugPoint(World, OutHit.ImpactPoint, 16.0f, TraceColor.ToFColor(true), bPersistent, LifeTime); + + DrawDebugCapsule(World, End, CollisionShape.GetCapsuleHalfHeight(), CollisionShape.GetCapsuleRadius(), FQuat::Identity, TraceHitColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugLine(World, OutHit.Location, End, TraceHitColor.ToFColor(true), bPersistent, LifeTime); + } + else + { + // no hit means all red + DrawDebugCapsule(World, Start, CollisionShape.GetCapsuleHalfHeight(), CollisionShape.GetCapsuleRadius(), FQuat::Identity, TraceColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugCapsule(World, End, CollisionShape.GetCapsuleHalfHeight(), CollisionShape.GetCapsuleRadius(), FQuat::Identity, TraceColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugLine(World, Start, End, TraceColor.ToFColor(true), bPersistent, LifeTime); + } + } +} + +static void DrawDebugSweptSphere(const UWorld* InWorld, + FVector const& Start, + FVector const& End, + float Radius, + FColor const& Color, + bool bPersistentLines = false, + float LifeTime = -1.f, + uint8 DepthPriority = 0) +{ + FVector const TraceVec = End - Start; + float const Dist = TraceVec.Size(); + + FVector const Center = Start + TraceVec * 0.5f; + float const HalfHeight = (Dist * 0.5f) + Radius; + + FQuat const CapsuleRot = FRotationMatrix::MakeFromZ(TraceVec).ToQuat(); + DrawDebugCapsule(InWorld, Center, HalfHeight, Radius, CapsuleRot, Color, bPersistentLines, LifeTime, DepthPriority); +} + +void UALSDebugComponent::DrawDebugSphereTraceSingle(const UWorld* World, + const FVector& Start, + const FVector& End, + const FCollisionShape& CollisionShape, + EDrawDebugTrace::Type DrawDebugType, + bool bHit, + const FHitResult& OutHit, + FLinearColor TraceColor, + FLinearColor TraceHitColor, + float DrawTime) +{ + if (DrawDebugType != EDrawDebugTrace::None) + { + bool bPersistent = DrawDebugType == EDrawDebugTrace::Persistent; + float LifeTime = (DrawDebugType == EDrawDebugTrace::ForDuration) ? DrawTime : 0.f; + + if (bHit && OutHit.bBlockingHit) + { + // Red up to the blocking hit, green thereafter + DrawDebugSweptSphere(World, Start, OutHit.Location, CollisionShape.GetSphereRadius(), TraceColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugSweptSphere(World, OutHit.Location, End, CollisionShape.GetSphereRadius(), TraceHitColor.ToFColor(true), bPersistent, LifeTime); + DrawDebugPoint(World, OutHit.ImpactPoint, 16.0f, TraceColor.ToFColor(true), bPersistent, LifeTime); + } + else + { + // no hit means all red + DrawDebugSweptSphere(World, Start, End, CollisionShape.GetSphereRadius(), TraceColor.ToFColor(true), bPersistent, LifeTime); + } + } +} \ No newline at end of file diff --git a/Source/ALSV4_CPP/Private/Components/ALSMantleComponent.cpp b/Source/ALSV4_CPP/Private/Components/ALSMantleComponent.cpp index f7c4cbd05..607cc0576 100644 --- a/Source/ALSV4_CPP/Private/Components/ALSMantleComponent.cpp +++ b/Source/ALSV4_CPP/Private/Components/ALSMantleComponent.cpp @@ -1,8 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Components/ALSMantleComponent.h" @@ -10,18 +7,26 @@ #include "Character/ALSCharacter.h" #include "Character/Animation/ALSCharacterAnimInstance.h" +#include "Components/ALSDebugComponent.h" #include "Curves/CurveVector.h" #include "GameFramework/CharacterMovementComponent.h" #include "Kismet/KismetMathLibrary.h" #include "Library/ALSMathLibrary.h" +const FName NAME_MantleEnd(TEXT("MantleEnd")); +const FName NAME_MantleUpdate(TEXT("MantleUpdate")); +const FName NAME_MantleTimeline(TEXT("MantleTimeline")); + +FName UALSMantleComponent::NAME_IgnoreOnlyPawn(TEXT("IgnoreOnlyPawn")); + + UALSMantleComponent::UALSMantleComponent() { PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bStartWithTickEnabled = true; - MantleTimeline = CreateDefaultSubobject(FName(TEXT("MantleTimeline"))); + MantleTimeline = CreateDefaultSubobject(NAME_MantleTimeline); } void UALSMantleComponent::BeginPlay() @@ -33,13 +38,15 @@ void UALSMantleComponent::BeginPlay() OwnerCharacter = Cast(GetOwner()); if (OwnerCharacter) { + ALSDebugComponent = OwnerCharacter->FindComponentByClass(); + AddTickPrerequisiteActor(OwnerCharacter); // Always tick after owner, so we'll use updated values // Bindings FOnTimelineFloat TimelineUpdated; FOnTimelineEvent TimelineFinished; - TimelineUpdated.BindUFunction(this, FName(TEXT("MantleUpdate"))); - TimelineFinished.BindUFunction(this, FName(TEXT("MantleEnd"))); + TimelineUpdated.BindUFunction(this, NAME_MantleUpdate); + TimelineFinished.BindUFunction(this, NAME_MantleEnd); MantleTimeline->SetTimelineFinishedFunc(TimelineFinished); MantleTimeline->SetLooping(false); MantleTimeline->SetTimelineLengthMode(TL_TimelineLength); @@ -58,12 +65,12 @@ void UALSMantleComponent::TickComponent(float DeltaTime, ELevelTick TickType, { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - if (OwnerCharacter->GetMovementState() == EALSMovementState::InAir) + if (OwnerCharacter && OwnerCharacter->GetMovementState() == EALSMovementState::InAir) { // Perform a mantle check if falling while movement input is pressed. if (OwnerCharacter->HasMovementInput()) { - MantleCheck(FallingTraceSettings); + MantleCheck(FallingTraceSettings, EDrawDebugTrace::Type::ForOneFrame); } } } @@ -91,13 +98,13 @@ void UALSMantleComponent::MantleStart(float MantleHeight, const FALSComponentAnd MantleParams.AnimMontage = MantleAsset.AnimMontage; MantleParams.PositionCorrectionCurve = MantleAsset.PositionCorrectionCurve; MantleParams.StartingOffset = MantleAsset.StartingOffset; - MantleParams.StartingPosition = FMath::GetMappedRangeValueClamped({MantleAsset.LowHeight, MantleAsset.HighHeight}, + MantleParams.StartingPosition = FMath::GetMappedRangeValueClamped({MantleAsset.LowHeight, MantleAsset.HighHeight}, { MantleAsset.LowStartPosition, MantleAsset.HighStartPosition }, MantleHeight); - MantleParams.PlayRate = FMath::GetMappedRangeValueClamped({MantleAsset.LowHeight, MantleAsset.HighHeight}, + MantleParams.PlayRate = FMath::GetMappedRangeValueClamped({MantleAsset.LowHeight, MantleAsset.HighHeight}, {MantleAsset.LowPlayRate, MantleAsset.HighPlayRate}, MantleHeight); @@ -108,7 +115,7 @@ void UALSMantleComponent::MantleStart(float MantleHeight, const FALSComponentAnd // Step 3: Set the Mantle Target and calculate the Starting Offset // (offset amount between the actor and target transform). MantleTarget = MantleLedgeWS.Transform; - MantleActualStartOffset = UALSMathLibrary::TransfromSub(OwnerCharacter->GetActorTransform(), MantleTarget); + MantleActualStartOffset = UALSMathLibrary::TransformSub(OwnerCharacter->GetActorTransform(), MantleTarget); // Step 4: Calculate the Animated Start Offset from the Target Location. // This would be the location the actual animation starts at relative to the Target Transform. @@ -116,7 +123,7 @@ void UALSMantleComponent::MantleStart(float MantleHeight, const FALSComponentAnd RotatedVector.Z = MantleParams.StartingOffset.Z; const FTransform StartOffset(MantleTarget.Rotator(), MantleTarget.GetLocation() - RotatedVector, FVector::OneVector); - MantleAnimatedStartOffset = UALSMathLibrary::TransfromSub(StartOffset, MantleTarget); + MantleAnimatedStartOffset = UALSMathLibrary::TransformSub(StartOffset, MantleTarget); // Step 5: Clear the Character Movement Mode and set the Movement State to Mantling OwnerCharacter->GetCharacterMovement()->SetMovementMode(MOVE_None); @@ -132,10 +139,10 @@ void UALSMantleComponent::MantleStart(float MantleHeight, const FALSComponentAnd MantleTimeline->SetPlayRate(MantleParams.PlayRate); MantleTimeline->PlayFromStart(); - // Step 7: Play the Anim Montaget if valid. - if (IsValid(MantleParams.AnimMontage)) + // Step 7: Play the Anim Montage if valid. + if (MantleParams.AnimMontage && OwnerCharacter->GetMesh()->GetAnimInstance()) { - OwnerCharacter->GetMainAnimInstance()->Montage_Play(MantleParams.AnimMontage, MantleParams.PlayRate, + OwnerCharacter->GetMesh()->GetAnimInstance()->Montage_Play(MantleParams.AnimMontage, MantleParams.PlayRate, EMontagePlayReturnType::MontageLength, MantleParams.StartingPosition, false); } @@ -149,9 +156,7 @@ bool UALSMantleComponent::MantleCheck(const FALSMantleTraceSettings& TraceSettin } // Step 1: Trace forward to find a wall / object the character cannot walk on. - const FVector& TraceDirection = OwnerCharacter->HasMovementInput() - ? OwnerCharacter->GetPlayerMovementInput() - : OwnerCharacter->GetActorForwardVector(); + const FVector& TraceDirection = OwnerCharacter->GetActorForwardVector(); const FVector& CapsuleBaseLocation = UALSMathLibrary::GetCapsuleBaseLocation( 2.0f, OwnerCharacter->GetCapsuleComponent()); FVector TraceStart = CapsuleBaseLocation + TraceDirection * -30.0f; @@ -166,8 +171,25 @@ bool UALSMantleComponent::MantleCheck(const FALSMantleTraceSettings& TraceSettin Params.AddIgnoredActor(OwnerCharacter); FHitResult HitResult; - World->SweepSingleByProfile(HitResult, TraceStart, TraceEnd, FQuat::Identity, MantleObjectDetectionProfile, - FCollisionShape::MakeCapsule(TraceSettings.ForwardTraceRadius, HalfHeight), Params); + { + const FCollisionShape CapsuleCollisionShape = FCollisionShape::MakeCapsule(TraceSettings.ForwardTraceRadius, HalfHeight); + const bool bHit = World->SweepSingleByProfile(HitResult, TraceStart, TraceEnd, FQuat::Identity, MantleObjectDetectionProfile, + CapsuleCollisionShape, Params); + + if (ALSDebugComponent && ALSDebugComponent->GetShowTraces()) + { + UALSDebugComponent::DrawDebugCapsuleTraceSingle(World, + TraceStart, + TraceEnd, + CapsuleCollisionShape, + DebugType, + bHit, + HitResult, + FLinearColor::Black, + FLinearColor::Black, + 1.0f); + } + } if (!HitResult.IsValidBlockingHit() || OwnerCharacter->GetCharacterMovement()->IsWalkable(HitResult)) { @@ -195,9 +217,26 @@ bool UALSMantleComponent::MantleCheck(const FALSMantleTraceSettings& TraceSettin FVector DownwardTraceStart = DownwardTraceEnd; DownwardTraceStart.Z += TraceSettings.MaxLedgeHeight + TraceSettings.DownwardTraceRadius + 1.0f; - World->SweepSingleByChannel(HitResult, DownwardTraceStart, DownwardTraceEnd, FQuat::Identity, - WalkableSurfaceDetectionChannel, FCollisionShape::MakeSphere(TraceSettings.DownwardTraceRadius), - Params); + { + const FCollisionShape SphereCollisionShape = FCollisionShape::MakeSphere(TraceSettings.DownwardTraceRadius); + const bool bHit = World->SweepSingleByChannel(HitResult, DownwardTraceStart, DownwardTraceEnd, FQuat::Identity, + WalkableSurfaceDetectionChannel, SphereCollisionShape, + Params); + + if (ALSDebugComponent && ALSDebugComponent->GetShowTraces()) + { + UALSDebugComponent::DrawDebugSphereTraceSingle(World, + TraceStart, + TraceEnd, + SphereCollisionShape, + DebugType, + bHit, + HitResult, + FLinearColor::Black, + FLinearColor::Black, + 1.0f); + } + } if (!OwnerCharacter->GetCharacterMovement()->IsWalkable(HitResult)) @@ -215,7 +254,7 @@ bool UALSMantleComponent::MantleCheck(const FALSMantleTraceSettings& TraceSettin DownTraceLocation, 2.0f, OwnerCharacter->GetCapsuleComponent()); const bool bCapsuleHasRoom = UALSMathLibrary::CapsuleHasRoomCheck(OwnerCharacter->GetCapsuleComponent(), CapsuleLocationFBase, 0.0f, - 0.0f); + 0.0f, DebugType, ALSDebugComponent && ALSDebugComponent->GetShowTraces()); if (!bCapsuleHasRoom) { @@ -268,7 +307,7 @@ void UALSMantleComponent::Multicast_MantleStart_Implementation(float MantleHeigh } } -// This function is called by "MantleTimeline" using BindUFunction in the AALSBaseCharacter::BeginPlay during the default settings initalization. +// This function is called by "MantleTimeline" using BindUFunction in UALSMantleComponent::BeginPlay during the default settings initialization. void UALSMantleComponent::MantleUpdate(float BlendIn) { if (!OwnerCharacter) @@ -322,13 +361,13 @@ void UALSMantleComponent::MantleUpdate(float BlendIn) // Blend from the currently blending transforms into the final mantle target using the X // value of the Position/Correction Curve. const FTransform& ResultLerp = UKismetMathLibrary::TLerp( - UALSMathLibrary::TransfromAdd(MantleTarget, ResultTransform), MantleTarget, + UALSMathLibrary::TransformAdd(MantleTarget, ResultTransform), MantleTarget, PositionAlpha); // Initial Blend In (controlled in the timeline curve) to allow the actor to blend into the Position/Correction - // curve at the midoint. This prevents pops when mantling an object lower than the animated mantle. + // curve at the midpoint. This prevents pops when mantling an object lower than the animated mantle. const FTransform& LerpedTarget = - UKismetMathLibrary::TLerp(UALSMathLibrary::TransfromAdd(MantleTarget, MantleActualStartOffset), ResultLerp, + UKismetMathLibrary::TLerp(UALSMathLibrary::TransformAdd(MantleTarget, MantleActualStartOffset), ResultLerp, BlendIn); // Step 4: Set the actors location and rotation to the Lerped Target. @@ -362,12 +401,12 @@ void UALSMantleComponent::OnOwnerJumpInput() { if (OwnerCharacter->HasMovementInput()) { - MantleCheck(GroundedTraceSettings); + MantleCheck(GroundedTraceSettings, EDrawDebugTrace::Type::ForDuration); } } else if (OwnerCharacter->GetMovementState() == EALSMovementState::InAir) { - MantleCheck(FallingTraceSettings); + MantleCheck(FallingTraceSettings, EDrawDebugTrace::Type::ForDuration); } } } diff --git a/Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp b/Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp index 295b16fa1..0872ca747 100644 --- a/Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp +++ b/Source/ALSV4_CPP/Private/Library/ALSMathLibrary.cpp @@ -1,13 +1,13 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #include "Library/ALSMathLibrary.h" + +#include "Library/ALSCharacterStructLibrary.h" +#include "Components/ALSDebugComponent.h" + #include "Components/CapsuleComponent.h" FTransform UALSMathLibrary::MantleComponentLocalToWorld(const FALSComponentAndTransform& CompAndTransform) @@ -19,17 +19,6 @@ FTransform UALSMathLibrary::MantleComponentLocalToWorld(const FALSComponentAndTr return {Quat, Location, Scale}; } -TPair UALSMathLibrary::FixDiagonalGamepadValues(const float X, const float Y) -{ - float ResultY = X * FMath::GetMappedRangeValueClamped(FVector2D(0.0f, 0.6f), - FVector2D(1.0f, 1.2f), FMath::Abs(Y)); - ResultY = FMath::Clamp(ResultY, -1.0f, 1.0f); - float ResultX = Y * FMath::GetMappedRangeValueClamped(FVector2D(0.0f, 0.6f), - FVector2D(1.0f, 1.2f), FMath::Abs(X)); - ResultX = FMath::Clamp(ResultX, -1.0f, 1.0f); - return TPair(ResultY, ResultX); -} - FVector UALSMathLibrary::GetCapsuleBaseLocation(const float ZOffset, UCapsuleComponent* Capsule) { return Capsule->GetComponentLocation() - @@ -44,7 +33,7 @@ FVector UALSMathLibrary::GetCapsuleLocationFromBase(FVector BaseLocation, const } bool UALSMathLibrary::CapsuleHasRoomCheck(UCapsuleComponent* Capsule, FVector TargetLocation, float HeightOffset, - float RadiusOffset) + float RadiusOffset, EDrawDebugTrace::Type DebugType, bool DrawDebugTrace) { // Perform a trace to see if the capsule has room to be at the target location. const float ZTarget = Capsule->GetScaledCapsuleHalfHeight_WithoutHemisphere() - RadiusOffset + HeightOffset; @@ -61,8 +50,23 @@ bool UALSMathLibrary::CapsuleHasRoomCheck(UCapsuleComponent* Capsule, FVector Ta Params.AddIgnoredActor(Capsule->GetOwner()); FHitResult HitResult; - World->SweepSingleByChannel(HitResult, TraceStart, TraceEnd, FQuat::Identity, - ECC_Visibility, FCollisionShape::MakeSphere(Radius), Params); + const FCollisionShape SphereCollisionShape = FCollisionShape::MakeSphere(Radius); + const bool bHit = World->SweepSingleByChannel(HitResult, TraceStart, TraceEnd, FQuat::Identity, + ECC_Visibility, FCollisionShape::MakeSphere(Radius), Params); + + if (DrawDebugTrace) + { + UALSDebugComponent::DrawDebugSphereTraceSingle(World, + TraceStart, + TraceEnd, + SphereCollisionShape, + DebugType, + bHit, + HitResult, + FLinearColor(0.130706f, 0.896269f, 0.144582f, 1.0f), // light green + FLinearColor(0.932733f, 0.29136f, 1.0f, 1.0f), // light purple + 1.0f); + } return !(HitResult.bBlockingHit || HitResult.bStartPenetrating); } @@ -84,19 +88,19 @@ EALSMovementDirection UALSMathLibrary::CalculateQuadrant(EALSMovementDirection C // Take the input angle and determine its quadrant (direction). Use the current Movement Direction to increase or // decrease the buffers on the angle ranges for each quadrant. if (AngleInRange(Angle, FLThreshold, FRThreshold, Buffer, - Current != EALSMovementDirection::Forward || Current != EALSMovementDirection::Backward)) + Current != EALSMovementDirection::Forward && Current != EALSMovementDirection::Backward)) { return EALSMovementDirection::Forward; } if (AngleInRange(Angle, FRThreshold, BRThreshold, Buffer, - Current != EALSMovementDirection::Right || Current != EALSMovementDirection::Left)) + Current != EALSMovementDirection::Right && Current != EALSMovementDirection::Left)) { return EALSMovementDirection::Right; } if (AngleInRange(Angle, BLThreshold, FLThreshold, Buffer, - Current != EALSMovementDirection::Right || Current != EALSMovementDirection::Left)) + Current != EALSMovementDirection::Right && Current != EALSMovementDirection::Left)) { return EALSMovementDirection::Left; } diff --git a/Source/ALSV4_CPP/Public/AI/ALSAIController.h b/Source/ALSV4_CPP/Public/AI/ALSAIController.h index c08281ecd..7d02ab709 100644 --- a/Source/ALSV4_CPP/Public/AI/ALSAIController.h +++ b/Source/ALSV4_CPP/Public/AI/ALSAIController.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Jens Bjarne Myhre -// Contributors: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -25,8 +21,10 @@ class ALSV4_CPP_API AALSAIController : public AAIController AALSAIController(); UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "AI") - UBehaviorTree* Behaviour = nullptr; + TObjectPtr Behaviour = nullptr; protected: virtual void OnPossess(APawn* InPawn) override; + + virtual FVector GetFocalPointOnActor(const AActor *Actor) const override; }; diff --git a/Source/ALSV4_CPP/Public/AI/ALS_BTTask_GetRandomLocation.h b/Source/ALSV4_CPP/Public/AI/ALS_BTTask_GetRandomLocation.h index ac4fe0059..c869b1976 100644 --- a/Source/ALSV4_CPP/Public/AI/ALS_BTTask_GetRandomLocation.h +++ b/Source/ALSV4_CPP/Public/AI/ALS_BTTask_GetRandomLocation.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Jens Bjarne Myhre -// Contributors: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -12,6 +8,8 @@ #include "BehaviorTree/Tasks/BTTask_BlackboardBase.h" #include "ALS_BTTask_GetRandomLocation.generated.h" +class UNavigationQueryFilter; + /** Picks a random location reachable through NavMesh within the Max Distance from the Owning Pawn's current location and assigns it to the specified Blackboard Key. */ UCLASS(Category=ALS, meta=(DisplayName = "Get Random Location")) class ALSV4_CPP_API UALS_BTTask_GetRandomLocation : public UBTTask_BlackboardBase diff --git a/Source/ALSV4_CPP/Public/AI/ALS_BTTask_SetFocusToPlayer.h b/Source/ALSV4_CPP/Public/AI/ALS_BTTask_SetFocusToPlayer.h index ada4bab47..44cddbe68 100644 --- a/Source/ALSV4_CPP/Public/AI/ALS_BTTask_SetFocusToPlayer.h +++ b/Source/ALSV4_CPP/Public/AI/ALS_BTTask_SetFocusToPlayer.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Jens Bjarne Myhre -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once diff --git a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h index da7e64353..372f146d3 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSBaseCharacter.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: Haziq Fadhil, Drakynfly, CanisHelix +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -17,15 +13,14 @@ #include "ALSBaseCharacter.generated.h" -class UTimelineComponent; -class UAnimInstance; +// forward declarations +class UALSDebugComponent; class UAnimMontage; -class UALSCharacterAnimInstance; class UALSPlayerCameraBehavior; enum class EVisibilityBasedAnimTickOption : uint8; DECLARE_DYNAMIC_MULTICAST_DELEGATE(FJumpPressedSignature); - +DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnJumpedSignature); DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FRagdollStateChangedSignature, bool, bRagdollState); /* @@ -49,10 +44,6 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter virtual void BeginPlay() override; - virtual void PreInitializeComponents() override; - - virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override; - virtual void PostInitializeComponents() override; virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; @@ -75,7 +66,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Character States */ UFUNCTION(BlueprintCallable, Category = "ALS|Character States") - void SetMovementState(EALSMovementState NewState); + void SetMovementState(EALSMovementState NewState, bool bForce = false); UFUNCTION(BlueprintGetter, Category = "ALS|Character States") EALSMovementState GetMovementState() const { return MovementState; } @@ -84,19 +75,25 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter EALSMovementState GetPrevMovementState() const { return PrevMovementState; } UFUNCTION(BlueprintCallable, Category = "ALS|Character States") - void SetMovementAction(EALSMovementAction NewAction); + void SetMovementAction(EALSMovementAction NewAction, bool bForce = false); UFUNCTION(BlueprintGetter, Category = "ALS|Character States") EALSMovementAction GetMovementAction() const { return MovementAction; } UFUNCTION(BlueprintCallable, Category = "ALS|Character States") - void SetStance(EALSStance NewStance); + void SetStance(EALSStance NewStance, bool bForce = false); UFUNCTION(BlueprintGetter, Category = "ALS|Character States") EALSStance GetStance() const { return Stance; } UFUNCTION(BlueprintCallable, Category = "ALS|Character States") - void SetGait(EALSGait NewGait); + void SetOverlayOverrideState(int32 NewState); + + UFUNCTION(BlueprintGetter, Category = "ALS|Character States") + int32 GetOverlayOverrideState() const { return OverlayOverrideState; } + + UFUNCTION(BlueprintCallable, Category = "ALS|Character States") + void SetGait(EALSGait NewGait, bool bForce = false); UFUNCTION(BlueprintGetter, Category = "ALS|Character States") EALSGait GetGait() const { return Gait; } @@ -105,34 +102,37 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter EALSGait GetDesiredGait() const { return DesiredGait; } UFUNCTION(BlueprintCallable, Category = "ALS|Character States") - void SetRotationMode(EALSRotationMode NewRotationMode); + void SetRotationMode(EALSRotationMode NewRotationMode, bool bForce = false); UFUNCTION(BlueprintCallable, Server, Reliable, Category = "ALS|Character States") - void Server_SetRotationMode(EALSRotationMode NewRotationMode); + void Server_SetRotationMode(EALSRotationMode NewRotationMode, bool bForce); UFUNCTION(BlueprintGetter, Category = "ALS|Character States") EALSRotationMode GetRotationMode() const { return RotationMode; } UFUNCTION(BlueprintCallable, Category = "ALS|Character States") - void SetViewMode(EALSViewMode NewViewMode); + void SetViewMode(EALSViewMode NewViewMode, bool bForce = false); UFUNCTION(BlueprintCallable, Server, Reliable, Category = "ALS|Character States") - void Server_SetViewMode(EALSViewMode NewViewMode); + void Server_SetViewMode(EALSViewMode NewViewMode, bool bForce); UFUNCTION(BlueprintGetter, Category = "ALS|Character States") EALSViewMode GetViewMode() const { return ViewMode; } UFUNCTION(BlueprintCallable, Category = "ALS|Character States") - void SetOverlayState(EALSOverlayState NewState); + void SetOverlayState(EALSOverlayState NewState, bool bForce = false); + + UFUNCTION(BlueprintCallable, Category = "ALS|Character States") + void SetGroundedEntryState(EALSGroundedEntryState NewState); UFUNCTION(BlueprintCallable, Server, Reliable, Category = "ALS|Character States") - void Server_SetOverlayState(EALSOverlayState NewState); + void Server_SetOverlayState(EALSOverlayState NewState, bool bForce); UFUNCTION(BlueprintGetter, Category = "ALS|Character States") EALSOverlayState GetOverlayState() const { return OverlayState; } UFUNCTION(BlueprintGetter, Category = "ALS|Character States") - EALSOverlayState SwitchRight() const { return OverlayState; } + EALSGroundedEntryState GetGroundedEntryState() const { return GroundedEntryState; } /** Landed, Jumped, Rolling, Mantling and Ragdoll*/ /** On Landed*/ @@ -180,6 +180,9 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UPROPERTY(BlueprintAssignable, Category = "ALS|Input") FJumpPressedSignature JumpPressedDelegate; + UPROPERTY(BlueprintAssignable, Category = "ALS|Input") + FOnJumpedSignature OnJumpedDelegate; + UPROPERTY(BlueprintAssignable, Category = "ALS|Input") FRagdollStateChangedSignature RagdollStateChangedDelegate; @@ -207,9 +210,6 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UFUNCTION(BlueprintCallable, Server, Reliable, Category = "ALS|Character States") void Server_SetDesiredRotationMode(EALSRotationMode NewRotMode); - UFUNCTION(BlueprintCallable, Category = "ALS|Input") - FVector GetPlayerMovementInput() const; - /** Rotation System */ UFUNCTION(BlueprintCallable, Category = "ALS|Rotation System") @@ -220,9 +220,6 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UFUNCTION(BlueprintGetter, Category = "ALS|Movement System") bool HasMovementInput() const { return bHasMovementInput; } - UFUNCTION(BlueprintCallable, Category = "ALS|Movement System") - void SetHasMovementInput(bool bNewHasMovementInput); - UFUNCTION(BlueprintCallable, Category = "ALS|Movement System") FALSMovementSettings GetTargetMovementSettings() const; @@ -251,9 +248,6 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Utility */ - UFUNCTION(BlueprintCallable, Category = "ALS|Utility") - UALSCharacterAnimInstance* GetMainAnimInstance() { return MainAnimInstance; } - UFUNCTION(BlueprintCallable, Category = "ALS|Utility") float GetAnimCurveValue(FName CurveName) const; @@ -291,41 +285,67 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UFUNCTION(BlueprintGetter, Category = "ALS|Essential Information") FVector GetAcceleration() const { return Acceleration; } - UFUNCTION(BlueprintCallable, Category = "ALS|Essential Information") - void SetAcceleration(const FVector& NewAcceleration); - UFUNCTION(BlueprintGetter, Category = "ALS|Essential Information") bool IsMoving() const { return bIsMoving; } - UFUNCTION(BlueprintCallable, Category = "ALS|Essential Information") - void SetIsMoving(bool bNewIsMoving); - UFUNCTION(BlueprintCallable, Category = "ALS|Essential Information") FVector GetMovementInput() const; UFUNCTION(BlueprintGetter, Category = "ALS|Essential Information") float GetMovementInputAmount() const { return MovementInputAmount; } - UFUNCTION(BlueprintCallable, Category = "ALS|Essential Information") - void SetMovementInputAmount(float NewMovementInputAmount); - UFUNCTION(BlueprintGetter, Category = "ALS|Essential Information") float GetSpeed() const { return Speed; } - UFUNCTION(BlueprintCallable, Category = "ALS|Essential Information") - void SetSpeed(float NewSpeed); - UFUNCTION(BlueprintCallable, Category = "ALS|Essential Information") FRotator GetAimingRotation() const { return AimingRotation; } UFUNCTION(BlueprintGetter, Category = "ALS|Essential Information") float GetAimYawRate() const { return AimYawRate; } - UFUNCTION(BlueprintCallable, Category = "ALS|Essential Information") - void SetAimYawRate(float NewAimYawRate); + /** Input */ - UFUNCTION(BlueprintCallable, Category = "ALS|Essential Information") - void GetControlForwardRightVector(FVector& Forward, FVector& Right) const; + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void ForwardMovementAction(float Value); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void RightMovementAction(float Value); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void CameraUpAction(float Value); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void CameraRightAction(float Value); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void JumpAction(bool bValue); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void SprintAction(bool bValue); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void AimAction(bool bValue); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void CameraTapAction(); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void CameraHeldAction(); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void StanceAction(); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void WalkAction(); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void RagdollAction(); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void VelocityDirectionAction(); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Input") + void LookingDirectionAction(); protected: /** Ragdoll System */ @@ -382,43 +402,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter void SetMovementModel(); - /** Input */ - - void PlayerForwardMovementInput(float Value); - - void PlayerRightMovementInput(float Value); - - void PlayerCameraUpInput(float Value); - - void PlayerCameraRightInput(float Value); - - void JumpPressedAction(); - - void JumpReleasedAction(); - - void SprintPressedAction(); - - void SprintReleasedAction(); - - void AimPressedAction(); - - void AimReleasedAction(); - - void CameraPressedAction(); - - void CameraReleasedAction(); - - void OnSwitchCameraMode(); - - void StancePressedAction(); - - void WalkPressedAction(); - - void RagdollPressedAction(); - - void VelocityDirectionPressedAction(); - - void LookingDirectionPressedAction(); + void ForceUpdateCharacterState(); /** Replication */ UFUNCTION(Category = "ALS|Replication") @@ -431,12 +415,12 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter void OnRep_OverlayState(EALSOverlayState PrevOverlayState); UFUNCTION(Category = "ALS|Replication") - void OnRep_VisibleMesh(USkeletalMesh* NewVisibleMesh); + void OnRep_VisibleMesh(const USkeletalMesh* PreviousSkeletalMesh); protected: /* Custom movement component*/ UPROPERTY() - UALSCharacterMovementComponent* MyCharacterMovementComponent; + TObjectPtr MyCharacterMovementComponent; /** Input */ @@ -458,12 +442,6 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UPROPERTY(EditDefaultsOnly, Category = "ALS|Input", BlueprintReadOnly) float RollDoubleTapTimeout = 0.3f; - UPROPERTY(EditDefaultsOnly, Category = "ALS|Input", BlueprintReadOnly) - float ViewModeSwitchHoldTime = 0.2f; - - UPROPERTY(Category = "ALS|Input", BlueprintReadOnly) - int32 TimesPressedStance = 0; - UPROPERTY(Category = "ALS|Input", BlueprintReadOnly) bool bBreakFall = false; @@ -481,11 +459,6 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Camera System") bool bRightShoulder = false; - /** State Values */ - - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|State Values", ReplicatedUsing = OnRep_OverlayState) - EALSOverlayState OverlayState = EALSOverlayState::Default; - /** Movement System */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "ALS|Movement System") @@ -530,10 +503,16 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** Replicated Skeletal Mesh Information*/ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|Skeletal Mesh", ReplicatedUsing = OnRep_VisibleMesh) - USkeletalMesh* VisibleMesh = nullptr; + TObjectPtr VisibleMesh = nullptr; /** State Values */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|State Values", ReplicatedUsing = OnRep_OverlayState) + EALSOverlayState OverlayState = EALSOverlayState::Default; + + UPROPERTY(BlueprintReadOnly, Category = "ALS|State Values") + EALSGroundedEntryState GroundedEntryState; + UPROPERTY(BlueprintReadOnly, Category = "ALS|State Values") EALSMovementState MovementState = EALSMovementState::None; @@ -555,6 +534,9 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "ALS|State Values", ReplicatedUsing = OnRep_ViewMode) EALSViewMode ViewMode = EALSViewMode::ThirdPerson; + UPROPERTY(BlueprintReadOnly, Category = "ALS|State Values") + int32 OverlayOverrideState = 0; + /** Movement System */ UPROPERTY(BlueprintReadOnly, Category = "ALS|Movement System") @@ -578,9 +560,8 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter bool bBreakfallOnLand = true; /** If player hits to the ground with an amount of velocity greater than specified value, switch to breakfall state */ - UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "ALS|Breakfall System", meta = (EditCondition = - "bBreakfallOnLand")) - float BreakfallOnLandVelocity = 600.0f; + UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "ALS|Breakfall System", meta = (EditCondition ="bBreakfallOnLand")) + float BreakfallOnLandVelocity = 700.0f; /** Ragdoll System */ @@ -593,8 +574,7 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter bool bRagdollOnLand = false; /** If player hits to the ground with an amount of velocity greater than specified value, switch to ragdoll state */ - UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "ALS|Ragdoll System", meta = (EditCondition = - "bRagdollOnLand")) + UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "ALS|Ragdoll System", meta = (EditCondition ="bRagdollOnLand")) float RagdollOnLandVelocity = 1000.0f; UPROPERTY(BlueprintReadOnly, Category = "ALS|Ragdoll System") @@ -615,27 +595,20 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /* Dedicated server mesh default visibility based anim tick option*/ EVisibilityBasedAnimTickOption DefVisBasedTickOp; + bool bPreRagdollURO = false; + /** Cached Variables */ FVector PreviousVelocity = FVector::ZeroVector; float PreviousAimYaw = 0.0f; - UPROPERTY(BlueprintReadOnly, Category = "ALS|Utility") - UALSCharacterAnimInstance* MainAnimInstance = nullptr; - UPROPERTY(BlueprintReadOnly, Category = "ALS|Camera") - UALSPlayerCameraBehavior* CameraBehavior; + TObjectPtr CameraBehavior; /** Last time the 'first' crouch/roll button is pressed */ float LastStanceInputTime = 0.0f; - /** Last time the camera action button is pressed */ - float CameraActionPressedTime = 0.0f; - - /* Timer to manage camera mode swap action */ - FTimerHandle OnCameraModeSwapTimer; - /* Timer to manage reset of braking friction factor after on landed event */ FTimerHandle OnLandedFrictionResetTimer; @@ -644,4 +617,8 @@ class ALSV4_CPP_API AALSBaseCharacter : public ACharacter /** We won't use curve based movement and a few other features on networked games */ bool bEnableNetworkOptimizations = false; + +private: + UPROPERTY() + TObjectPtr ALSDebugComponent = nullptr; }; diff --git a/Source/ALSV4_CPP/Public/Character/ALSCharacter.h b/Source/ALSV4_CPP/Public/Character/ALSCharacter.h index d9b271607..2483ec67f 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSCharacter.h +++ b/Source/ALSV4_CPP/Public/Character/ALSCharacter.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -57,13 +53,13 @@ class ALSV4_CPP_API AALSCharacter : public AALSBaseCharacter public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS|Component") - USceneComponent* HeldObjectRoot = nullptr; + TObjectPtr HeldObjectRoot = nullptr; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS|Component") - USkeletalMeshComponent* SkeletalMesh = nullptr; + TObjectPtr SkeletalMesh = nullptr; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS|Component") - UStaticMeshComponent* StaticMesh = nullptr; + TObjectPtr StaticMesh = nullptr; private: bool bNeedsColorReset = false; diff --git a/Source/ALSV4_CPP/Public/Character/ALSCharacterMovementComponent.h b/Source/ALSV4_CPP/Public/Character/ALSCharacterMovementComponent.h index e70d4da32..7689a4653 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSCharacterMovementComponent.h +++ b/Source/ALSV4_CPP/Public/Character/ALSCharacterMovementComponent.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Haziq Fadhil -// Contributors: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -21,7 +17,7 @@ class ALSV4_CPP_API UALSCharacterMovementComponent : public UCharacterMovementCo { GENERATED_UCLASS_BODY() - class FSavedMove_My : public FSavedMove_Character + class ALSV4_CPP_API FSavedMove_My : public FSavedMove_Character { public: @@ -31,12 +27,14 @@ class ALSV4_CPP_API UALSCharacterMovementComponent : public UCharacterMovementCo virtual uint8 GetCompressedFlags() const override; virtual void SetMoveFor(ACharacter* Character, float InDeltaTime, FVector const& NewAccel, class FNetworkPredictionData_Client_Character& ClientData) override; + virtual void PrepMoveFor(class ACharacter* Character) override; // Walk Speed Update uint8 bSavedRequestMovementSettingsChange : 1; + EALSGait SavedAllowedGait = EALSGait::Walking; }; - class FNetworkPredictionData_Client_My : public FNetworkPredictionData_Client_Character + class ALSV4_CPP_API FNetworkPredictionData_Client_My : public FNetworkPredictionData_Client_Character { public: FNetworkPredictionData_Client_My(const UCharacterMovementComponent& ClientMovement); @@ -60,11 +58,11 @@ class ALSV4_CPP_API UALSCharacterMovementComponent : public UCharacterMovementCo uint8 bRequestMovementSettingsChange = 1; UPROPERTY() - float NewMaxWalkSpeed = 0; + EALSGait AllowedGait = EALSGait::Walking; UPROPERTY(BlueprintReadOnly, Category = "ALS|Movement System") FALSMovementSettings CurrentMovementSettings; - + // Set Movement Curve (Called in every instance) float GetMappedSpeed() const; @@ -73,8 +71,8 @@ class ALSV4_CPP_API UALSCharacterMovementComponent : public UCharacterMovementCo // Set Max Walking Speed (Called from the owning client) UFUNCTION(BlueprintCallable, Category = "Movement Settings") - void SetMaxWalkingSpeed(float UpdateMaxWalkSpeed); + void SetAllowedGait(EALSGait NewAllowedGait); UFUNCTION(Reliable, Server, Category = "Movement Settings") - void Server_SetMaxWalkingSpeed(float UpdateMaxWalkSpeed); + void Server_SetAllowedGait(EALSGait NewAllowedGait); }; diff --git a/Source/ALSV4_CPP/Public/Character/ALSPlayerCameraManager.h b/Source/ALSV4_CPP/Public/Character/ALSPlayerCameraManager.h index b05a956d2..d174ca9a7 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSPlayerCameraManager.h +++ b/Source/ALSV4_CPP/Public/Character/ALSPlayerCameraManager.h @@ -1,10 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: - +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -12,6 +7,8 @@ #include "Camera/PlayerCameraManager.h" #include "ALSPlayerCameraManager.generated.h" +// forward declarations +class UALSDebugComponent; class AALSBaseCharacter; /** @@ -47,10 +44,10 @@ class ALSV4_CPP_API AALSPlayerCameraManager : public APlayerCameraManager public: UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "ALS|Camera") - AALSBaseCharacter* ControlledCharacter = nullptr; + TObjectPtr ControlledCharacter = nullptr; UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "ALS|Camera") - USkeletalMeshComponent* CameraBehavior = nullptr; + TObjectPtr CameraBehavior = nullptr; protected: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "ALS|Camera") @@ -73,4 +70,8 @@ class ALSV4_CPP_API AALSPlayerCameraManager : public APlayerCameraManager UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Camera") FVector DebugViewOffset; + +private: + UPROPERTY() + TObjectPtr ALSDebugComponent = nullptr; }; diff --git a/Source/ALSV4_CPP/Public/Character/ALSPlayerController.h b/Source/ALSV4_CPP/Public/Character/ALSPlayerController.h index 399edd149..1b80fc209 100644 --- a/Source/ALSV4_CPP/Public/Character/ALSPlayerController.h +++ b/Source/ALSV4_CPP/Public/Character/ALSPlayerController.h @@ -1,17 +1,15 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: Drakynfly +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once #include "CoreMinimal.h" +#include "InputActionValue.h" #include "GameFramework/PlayerController.h" #include "ALSPlayerController.generated.h" class AALSBaseCharacter; +class UInputMappingContext; /** * Player controller class @@ -26,15 +24,99 @@ class ALSV4_CPP_API AALSPlayerController : public APlayerController virtual void OnRep_Pawn() override; - virtual void BeginPlayingState() override; + virtual void SetupInputComponent() override; + + virtual void BindActions(UInputMappingContext* Context); + +protected: + void SetupInputs(); -private: void SetupCamera(); - void SetupDebugInputs(); - + UFUNCTION() + void ForwardMovementAction(const FInputActionValue& Value); + + UFUNCTION() + void RightMovementAction(const FInputActionValue& Value); + + UFUNCTION() + void CameraUpAction(const FInputActionValue& Value); + + UFUNCTION() + void CameraRightAction(const FInputActionValue& Value); + + UFUNCTION() + void JumpAction(const FInputActionValue& Value); + + UFUNCTION() + void SprintAction(const FInputActionValue& Value); + + UFUNCTION() + void AimAction(const FInputActionValue& Value); + + UFUNCTION() + void CameraTapAction(const FInputActionValue& Value); + + UFUNCTION() + void CameraHeldAction(const FInputActionValue& Value); + + UFUNCTION() + void StanceAction(const FInputActionValue& Value); + + UFUNCTION() + void WalkAction(const FInputActionValue& Value); + + UFUNCTION() + void RagdollAction(const FInputActionValue& Value); + + UFUNCTION() + void VelocityDirectionAction(const FInputActionValue& Value); + + UFUNCTION() + void LookingDirectionAction(const FInputActionValue& Value); + + // Debug actions + UFUNCTION() + void DebugToggleHudAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugToggleDebugViewAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugToggleTracesAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugToggleShapesAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugToggleLayerColorsAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugToggleCharacterInfoAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugToggleSlomoAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugFocusedCharacterCycleAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugToggleMeshAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugOpenOverlayMenuAction(const FInputActionValue& Value); + + UFUNCTION() + void DebugOverlayMenuCycleAction(const FInputActionValue& Value); + public: /** Main character reference */ - UPROPERTY(BlueprintReadOnly, Category = "ALS Player Controller") - AALSBaseCharacter* PossessedCharacter = nullptr; + UPROPERTY(BlueprintReadOnly, Category = "ALS") + TObjectPtr PossessedCharacter = nullptr; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Input") + TObjectPtr DefaultInputMappingContext = nullptr; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Input") + TObjectPtr DebugInputMappingContext = nullptr; }; diff --git a/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h b/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h index 666a16136..a4afa5ac9 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/ALSCharacterAnimInstance.h @@ -1,10 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: - +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -15,6 +10,8 @@ #include "ALSCharacterAnimInstance.generated.h" +// forward declarations +class UALSDebugComponent; class AALSBaseCharacter; class UCurveFloat; class UAnimSequence; @@ -31,6 +28,8 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance public: virtual void NativeInitializeAnimation() override; + virtual void NativeBeginPlay() override; + virtual void NativeUpdateAnimation(float DeltaSeconds) override; UFUNCTION(BlueprintCallable, Category = "ALS|Animation") @@ -48,22 +47,18 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance UFUNCTION(BlueprintCallable, Category = "ALS|Event") void OnPivot(); - UFUNCTION(BlueprintCallable, Category = "ALS|Grounded") - void SetGroundedEntryState(EALSGroundedEntryState NewGroundedEntryState) - { - GroundedEntryState = NewGroundedEntryState; - } +protected: UFUNCTION(BlueprintCallable, Category = "ALS|Grounded") - void SetOverlayOverrideState(int32 OverlayOverrideState) + void SetTrackedHipsDirection(EALSHipsDirection HipsDirection) { - LayerBlendingValues.OverlayOverrideState = OverlayOverrideState; + Grounded.TrackedHipsDirection = HipsDirection; } UFUNCTION(BlueprintCallable, Category = "ALS|Grounded") - void SetTrackedHipsDirection(EALSHipsDirection HipsDirection) + void SetGroundedEntryState(EALSGroundedEntryState NewState) { - Grounded.TrackedHipsDirection = HipsDirection; + GroundedEntryState = NewState; } /** Enable Movement Animations if IsMoving and HasMovementInput, or if the Speed is greater than 150. */ @@ -90,12 +85,6 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance UFUNCTION(BlueprintCallable, Category = "ALS|Grounded") bool CanDynamicTransition() const; - /** Return mutable reference of character information to edit them easily inside character class */ - FALSAnimCharacterInformation& GetCharacterInformationMutable() - { - return CharacterInformation; - } - private: void PlayDynamicTransitionDelay(); @@ -170,17 +159,16 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance float GetAnimCurveClamped(const FName& Name, float Bias, float ClampMin, float ClampMax) const; -protected: +public: /** References */ UPROPERTY(BlueprintReadOnly, Category = "Read Only Data|Character Information") - AALSBaseCharacter* Character = nullptr; + TObjectPtr Character = nullptr; /** Character Information */ UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Character Information", Meta = ( ShowOnlyInnerProperties)) FALSAnimCharacterInformation CharacterInformation; -public: UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Character Information") FALSMovementState MovementState = EALSMovementState::None; @@ -188,7 +176,7 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance FALSMovementAction MovementAction = EALSMovementAction::None; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Character Information") - FALSRotationMode RotationMode = EALSRotationMode::LookingDirection; + FALSRotationMode RotationMode = EALSRotationMode::VelocityDirection; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Character Information") FALSGait Gait = EALSGait::Walking; @@ -199,13 +187,11 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Character Information") FALSOverlayState OverlayState = EALSOverlayState::Default; -protected: /** Anim Graph - Grounded */ UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Grounded", Meta = ( ShowOnlyInnerProperties)) FALSAnimGraphGrounded Grounded; -public: UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Grounded") FALSVelocityBlend VelocityBlend; @@ -221,7 +207,6 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Grounded") FALSMovementDirection MovementDirection = EALSMovementDirection::Forward; -protected: /** Anim Graph - In Air */ UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - In Air", Meta = ( ShowOnlyInnerProperties)) @@ -232,11 +217,9 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance ShowOnlyInnerProperties)) FALSAnimGraphAimingValues AimingValues; -public: UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Aiming Values") FVector2D SmoothedAimingAngle = FVector2D::ZeroVector; -protected: /** Anim Graph - Ragdoll */ UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Read Only Data|Anim Graph - Ragdoll") float FlailRate = 0.0f; @@ -269,39 +252,39 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance /** Blend Curves */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* DiagonalScaleAmountCurve = nullptr; + TObjectPtr DiagonalScaleAmountCurve = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* StrideBlend_N_Walk = nullptr; + TObjectPtr StrideBlend_N_Walk = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* StrideBlend_N_Run = nullptr; + TObjectPtr StrideBlend_N_Run = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* StrideBlend_C_Walk = nullptr; + TObjectPtr StrideBlend_C_Walk = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* LandPredictionCurve = nullptr; + TObjectPtr LandPredictionCurve = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveFloat* LeanInAirCurve = nullptr; + TObjectPtr LeanInAirCurve = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveVector* YawOffset_FB = nullptr; + TObjectPtr YawOffset_FB = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Blend Curves") - UCurveVector* YawOffset_LR = nullptr; + TObjectPtr YawOffset_LR = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Dynamic Transition") - UAnimSequenceBase* TransitionAnim_R = nullptr; + TObjectPtr TransitionAnim_R = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Dynamic Transition") - UAnimSequenceBase* TransitionAnim_L = nullptr; + TObjectPtr TransitionAnim_L = nullptr; /** IK Bone Names */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Anim Graph - Foot IK") FName IkFootL_BoneName = FName(TEXT("ik_foot_l")); - + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Configuration|Anim Graph - Foot IK") FName IkFootR_BoneName = FName(TEXT("ik_foot_r")); @@ -313,4 +296,7 @@ class ALSV4_CPP_API UALSCharacterAnimInstance : public UAnimInstance FTimerHandle OnJumpedTimer; bool bCanPlayDynamicTransition = true; + + UPROPERTY() + TObjectPtr ALSDebugComponent = nullptr; }; diff --git a/Source/ALSV4_CPP/Public/Character/Animation/ALSPlayerCameraBehavior.h b/Source/ALSV4_CPP/Public/Character/Animation/ALSPlayerCameraBehavior.h index d75777c51..86b157abd 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/ALSPlayerCameraBehavior.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/ALSPlayerCameraBehavior.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyCameraShake.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyCameraShake.h index bdfc3179d..40313040d 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyCameraShake.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyCameraShake.h @@ -1,18 +1,15 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once #include "CoreMinimal.h" +#include "Camera/CameraShakeBase.h" #include "Animation/AnimNotifies/AnimNotify.h" #include "ALSAnimNotifyCameraShake.generated.h" -class UMatineeCameraShake; +class UCameraShakeBase; /** * Generic camera shake animation notify for pawns with controller enabled @@ -22,7 +19,7 @@ class ALSV4_CPP_API UALSAnimNotifyCameraShake : public UAnimNotify { GENERATED_BODY() - virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyFootstep.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyFootstep.h index 85a2a79b8..afc6cebb6 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyFootstep.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyFootstep.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -25,16 +21,17 @@ class ALSV4_CPP_API UALSAnimNotifyFootstep : public UAnimNotify { GENERATED_BODY() - virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) override; virtual FString GetNotifyName_Implementation() const override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings") - UDataTable* HitDataTable; + TObjectPtr HitDataTable; + static FName NAME_Foot_R; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Socket") - FName FootSocketName = FName(TEXT("Foot_R")); + FName FootSocketName = NAME_Foot_R; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Trace") TEnumAsByte TraceChannel; @@ -60,8 +57,9 @@ class ALSV4_CPP_API UALSAnimNotifyFootstep : public UAnimNotify UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sound") bool bSpawnSound = true; + static FName NAME_FootstepType; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sound") - FName SoundParameterName = FName(TEXT("FootstepType")); + FName SoundParameterName = NAME_FootstepType; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sound") EALSFootstepType FootstepType = EALSFootstepType::Step; diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h index 3c4bbcf71..60d15479d 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSAnimNotifyGroundedEntryState.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -22,7 +18,7 @@ class ALSV4_CPP_API UALSAnimNotifyGroundedEntryState : public UAnimNotify { GENERATED_BODY() - virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) override; virtual FString GetNotifyName_Implementation() const override; diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h index c8664cfc6..b5a9bf0e5 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateEarlyBlendOut.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -22,14 +18,14 @@ class ALSV4_CPP_API UALSNotifyStateEarlyBlendOut : public UAnimNotifyState { GENERATED_BODY() - virtual void NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, - float FrameDeltaTime) override; + virtual void NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime, + const FAnimNotifyEventReference& EventReference) override; virtual FString GetNotifyName_Implementation() const override; public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) - UAnimMontage* ThisMontage = nullptr; + TObjectPtr ThisMontage = nullptr; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AnimNotify) float BlendOutTime = 0.25f; diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateMovementAction.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateMovementAction.h index 79e8544ea..b49e8615d 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateMovementAction.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateMovementAction.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -22,10 +18,11 @@ class ALSV4_CPP_API UALSNotifyStateMovementAction : public UAnimNotifyState { GENERATED_BODY() - virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, - float TotalDuration) override; + virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration, + const FAnimNotifyEventReference& EventReference) override; - virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, + const FAnimNotifyEventReference& EventReference) override; virtual FString GetNotifyName_Implementation() const override; diff --git a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateOverlayOverride.h b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateOverlayOverride.h index 0f9e8a749..096f19004 100644 --- a/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateOverlayOverride.h +++ b/Source/ALSV4_CPP/Public/Character/Animation/Notify/ALSNotifyStateOverlayOverride.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -20,10 +16,11 @@ class ALSV4_CPP_API UALSNotifyStateOverlayOverride : public UAnimNotifyState { GENERATED_BODY() - virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, - float TotalDuration) override; + virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration, + const FAnimNotifyEventReference& EventReference) override; - virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override; + virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, + const FAnimNotifyEventReference& EventReference) override; virtual FString GetNotifyName_Implementation() const override; diff --git a/Source/ALSV4_CPP/Public/Components/ALSDebugComponent.h b/Source/ALSV4_CPP/Public/Components/ALSDebugComponent.h index 783fb3ce0..4e355fa38 100644 --- a/Source/ALSV4_CPP/Public/Components/ALSDebugComponent.h +++ b/Source/ALSV4_CPP/Public/Components/ALSDebugComponent.h @@ -1,18 +1,17 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once #include "CoreMinimal.h" +#include "Kismet/KismetSystemLibrary.h" +#include "CollisionShape.h" #include "Components/ActorComponent.h" #include "ALSDebugComponent.generated.h" -class AALSCharacter; +class AALSBaseCharacter; +class USkeletalMesh; UCLASS(Blueprintable, BlueprintType) class ALSV4_CPP_API UALSDebugComponent : public UActorComponent @@ -22,6 +21,11 @@ class ALSV4_CPP_API UALSDebugComponent : public UActorComponent public: UALSDebugComponent(); + virtual void BeginPlay() override; + + UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "ALS|Debug") + void OnPlayerControllerInitialized(APlayerController* Controller); + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; @@ -55,6 +59,12 @@ class ALSV4_CPP_API UALSDebugComponent : public UActorComponent UFUNCTION(BlueprintCallable, Category = "ALS|Debug") void ToggleDebugView(); + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Debug") + void OpenOverlayMenu(bool bValue); + + UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALS|Debug") + void OverlayMenuCycle(bool bValue); + UFUNCTION(BlueprintCallable, Category = "ALS|Debug") void ToggleDebugMesh(); @@ -82,12 +92,51 @@ class ALSV4_CPP_API UALSDebugComponent : public UActorComponent UFUNCTION(BlueprintCallable, Category = "ALS|Debug") bool GetShowLayerColors() { return bShowLayerColors; } + UFUNCTION(BlueprintCallable, Category = "ALS|Debug") + void FocusedDebugCharacterCycle(bool bValue); + + // utility functions to draw trace debug shapes, + // which are derived from Engine/Private/KismetTraceUtils.h. + // Sadly the functions are private, which was the reason + // why there reimplemented here. + static void DrawDebugLineTraceSingle(const UWorld* World, + const FVector& Start, + const FVector& End, + EDrawDebugTrace::Type DrawDebugType, + bool bHit, + const FHitResult& OutHit, + FLinearColor TraceColor, + FLinearColor TraceHitColor, + float DrawTime); + + static void DrawDebugCapsuleTraceSingle(const UWorld* World, + const FVector& Start, + const FVector& End, + const FCollisionShape& CollisionShape, + EDrawDebugTrace::Type DrawDebugType, + bool bHit, + const FHitResult& OutHit, + FLinearColor TraceColor, + FLinearColor TraceHitColor, + float DrawTime); + + static void DrawDebugSphereTraceSingle(const UWorld* World, + const FVector& Start, + const FVector& End, + const FCollisionShape& CollisionShape, + EDrawDebugTrace::Type DrawDebugType, + bool bHit, + const FHitResult& OutHit, + FLinearColor TraceColor, + FLinearColor TraceHitColor, + float DrawTime); + protected: - virtual void BeginPlay() override; + void DetectDebuggableCharactersInWorld(); public: UPROPERTY(BlueprintReadOnly, Category = "ALS|Debug") - AALSCharacter* OwnerCharacter; + TObjectPtr OwnerCharacter; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|Debug") bool bSlomo = false; @@ -99,8 +148,14 @@ class ALSV4_CPP_API UALSDebugComponent : public UActorComponent bool bShowCharacterInfo = false; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|Debug") - USkeletalMesh* DebugSkeletalMesh = nullptr; + TObjectPtr DebugSkeletalMesh = nullptr; + + UPROPERTY(BlueprintReadOnly, Category = "ALS|Debug") + TArray> AvailableDebugCharacters; + UPROPERTY(BlueprintReadOnly, Category = "ALS|Debug") + TObjectPtr DebugFocusCharacter = nullptr; +private: static bool bDebugView; static bool bShowTraces; @@ -109,11 +164,14 @@ class ALSV4_CPP_API UALSDebugComponent : public UActorComponent static bool bShowLayerColors; -private: bool bNeedsColorReset = false; bool bDebugMeshVisible = false; UPROPERTY() - USkeletalMesh* DefaultSkeletalMesh = nullptr; + TObjectPtr DefaultSkeletalMesh = nullptr; + + /// Stores the index, which is used to select the next focused debug ALSBaseCharacter. + /// If no characters where found during BeginPlay the value should be set to INDEX_NONE. + int32 FocusedDebugCharacterIndex = INDEX_NONE; }; diff --git a/Source/ALSV4_CPP/Public/Components/ALSMantleComponent.h b/Source/ALSV4_CPP/Public/Components/ALSMantleComponent.h index 873e71f4d..6113b6fc6 100644 --- a/Source/ALSV4_CPP/Public/Components/ALSMantleComponent.h +++ b/Source/ALSV4_CPP/Public/Components/ALSMantleComponent.h @@ -1,8 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -14,6 +11,9 @@ #include "ALSMantleComponent.generated.h" +// forward declarations +class UALSDebugComponent; + UCLASS(Blueprintable, BlueprintType) class ALSV4_CPP_API UALSMantleComponent : public UActorComponent @@ -23,12 +23,9 @@ class ALSV4_CPP_API UALSMantleComponent : public UActorComponent public: UALSMantleComponent(); - virtual void TickComponent(float DeltaTime, ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) override; - UFUNCTION(BlueprintCallable, Category = "ALS|Mantle System") bool MantleCheck(const FALSMantleTraceSettings& TraceSettings, - EDrawDebugTrace::Type DebugType = EDrawDebugTrace::Type::None); + EDrawDebugTrace::Type DebugType); UFUNCTION(BlueprintCallable, Category = "ALS|Mantle System") void MantleStart(float MantleHeight, const FALSComponentAndTransform& MantleLedgeWS, @@ -51,6 +48,9 @@ class ALSV4_CPP_API UALSMantleComponent : public UActorComponent FALSMantleAsset GetMantleAsset(EALSMantleType MantleType, EALSOverlayState CurrentOverlayState); protected: + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; + // Called when the game starts virtual void BeginPlay() override; @@ -65,7 +65,7 @@ class ALSV4_CPP_API UALSMantleComponent : public UActorComponent protected: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS|Mantle System") - UTimelineComponent* MantleTimeline = nullptr; + TObjectPtr MantleTimeline = nullptr; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") FALSMantleTraceSettings GroundedTraceSettings; @@ -77,11 +77,12 @@ class ALSV4_CPP_API UALSMantleComponent : public UActorComponent FALSMantleTraceSettings FallingTraceSettings; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") - UCurveFloat* MantleTimelineCurve; + TObjectPtr MantleTimelineCurve; + static FName NAME_IgnoreOnlyPawn; /** Profile to use to detect objects we allow mantling */ UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") - FName MantleObjectDetectionProfile = FName(TEXT("IgnoreOnlyPawn")); + FName MantleObjectDetectionProfile = NAME_IgnoreOnlyPawn; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "ALS|Mantle System") TEnumAsByte WalkableSurfaceDetectionChannel = ECC_Visibility; @@ -107,5 +108,8 @@ class ALSV4_CPP_API UALSMantleComponent : public UActorComponent private: UPROPERTY() - AALSBaseCharacter* OwnerCharacter; + TObjectPtr OwnerCharacter; + + UPROPERTY() + TObjectPtr ALSDebugComponent = nullptr; }; diff --git a/Source/ALSV4_CPP/Public/Library/ALSAnimationStructLibrary.h b/Source/ALSV4_CPP/Public/Library/ALSAnimationStructLibrary.h index e483bd14d..69ce6fe65 100644 --- a/Source/ALSV4_CPP/Public/Library/ALSAnimationStructLibrary.h +++ b/Source/ALSV4_CPP/Public/Library/ALSAnimationStructLibrary.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -22,7 +18,7 @@ struct FALSDynamicMontageParams GENERATED_BODY() UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS|Dynamic Transition") - UAnimSequenceBase* Animation = nullptr; + TObjectPtr Animation = nullptr; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ALS|Dynamic Transition") float BlendInTime = 0.0f; @@ -73,13 +69,13 @@ struct FALSTurnInPlaceAsset GENERATED_BODY() UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|Turn In Place") - UAnimSequenceBase* Animation = nullptr; + TObjectPtr Animation = nullptr; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|Turn In Place") float AnimatedAngle = 0.0f; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|Turn In Place") - FName SlotName; + FName SlotName = NAME_None; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "ALS|Turn In Place") float PlayRate = 1.0f; @@ -94,22 +90,22 @@ struct FALSAnimCharacterInformation GENERATED_BODY() UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Character Information") - FRotator AimingRotation; + FRotator AimingRotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Character Information") - FRotator CharacterActorRotation; + FRotator CharacterActorRotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Character Information") - FVector Velocity; + FVector Velocity = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Character Information") - FVector RelativeVelocityDirection; + FVector RelativeVelocityDirection = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Character Information") - FVector Acceleration; + FVector Acceleration = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Character Information") - FVector MovementInput; + FVector MovementInput = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Character Information") bool bIsMoving = false; @@ -214,13 +210,13 @@ struct FALSAnimGraphAimingValues GENERATED_BODY() UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Aiming Values") - FRotator SmoothedAimingRotation; + FRotator SmoothedAimingRotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Aiming Values") - FRotator SpineRotation; + FRotator SpineRotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Aiming Values") - FVector2D AimingAngle; + FVector2D AimingAngle = FVector2D::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Aiming Values") float AimSweepTime = 0.5f; @@ -328,46 +324,46 @@ struct FALSAnimGraphFootIK float FootLock_R_Alpha = 0.0f; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - bool UseFootLockCurve_L; + bool UseFootLockCurve_L = false; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - bool UseFootLockCurve_R; + bool UseFootLockCurve_R = false; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FVector FootLock_L_Location; + FVector FootLock_L_Location = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FVector TargetFootLock_R_Location; + FVector TargetFootLock_R_Location = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FVector FootLock_R_Location; + FVector FootLock_R_Location = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FRotator TargetFootLock_L_Rotation; + FRotator TargetFootLock_L_Rotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FRotator FootLock_L_Rotation; + FRotator FootLock_L_Rotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FRotator TargetFootLock_R_Rotation; + FRotator TargetFootLock_R_Rotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FRotator FootLock_R_Rotation; + FRotator FootLock_R_Rotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FVector FootOffset_L_Location; + FVector FootOffset_L_Location = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FVector FootOffset_R_Location; + FVector FootOffset_R_Location = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FRotator FootOffset_L_Rotation; + FRotator FootOffset_L_Rotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FRotator FootOffset_R_Rotation; + FRotator FootOffset_R_Rotation = FRotator::ZeroRotator; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") - FVector PelvisOffset; + FVector PelvisOffset = FVector::ZeroVector; UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "ALS|Anim Graph - Foot IK") float PelvisAlpha = 0.0f; diff --git a/Source/ALSV4_CPP/Public/Library/ALSCharacterEnumLibrary.h b/Source/ALSV4_CPP/Public/Library/ALSCharacterEnumLibrary.h index 2d283c577..5b9e4055b 100644 --- a/Source/ALSV4_CPP/Public/Library/ALSCharacterEnumLibrary.h +++ b/Source/ALSV4_CPP/Public/Library/ALSCharacterEnumLibrary.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once @@ -28,7 +24,7 @@ static FORCEINLINE FString GetEnumerationToString(const Enumeration InValue) /** * Character gait state. Note: Also edit related struct in ALSStructEnumLibrary if you add new enums */ -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_Gait")) enum class EALSGait : uint8 { Walking, @@ -39,7 +35,7 @@ enum class EALSGait : uint8 /** * Character movement action state. Note: Also edit related struct in ALSStructEnumLibrary if you add new enums */ -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_MovementAction")) enum class EALSMovementAction : uint8 { None, @@ -52,7 +48,7 @@ enum class EALSMovementAction : uint8 /** * Character movement state. Note: Also edit related struct in ALSStructEnumLibrary if you add new enums */ -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_MovementState")) enum class EALSMovementState : uint8 { None, @@ -65,7 +61,7 @@ enum class EALSMovementState : uint8 /** * Character overlay state. Note: Also edit related struct in ALSStructEnumLibrary if you add new enums */ -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_OverlayState")) enum class EALSOverlayState : uint8 { Default, @@ -86,7 +82,7 @@ enum class EALSOverlayState : uint8 /** * Character rotation mode. Note: Also edit related struct in ALSStructEnumLibrary if you add new enums */ -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName="ALS_RotationMode")) enum class EALSRotationMode : uint8 { VelocityDirection, @@ -97,7 +93,7 @@ enum class EALSRotationMode : uint8 /** * Character stance. Note: Also edit related struct in ALSStructEnumLibrary if you add new enums */ -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_Stance")) enum class EALSStance : uint8 { Standing, @@ -107,14 +103,14 @@ enum class EALSStance : uint8 /** * Character view mode. Note: Also edit related struct in ALSStructEnumLibrary if you add new enums */ -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_ViewMode")) enum class EALSViewMode : uint8 { ThirdPerson, FirstPerson }; -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_AnimFeatureExample")) enum class EALSAnimFeatureExample : uint8 { StrideBlending, @@ -122,7 +118,7 @@ enum class EALSAnimFeatureExample : uint8 SprintImpulse }; -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_FootstepType")) enum class EALSFootstepType : uint8 { Step, @@ -131,14 +127,14 @@ enum class EALSFootstepType : uint8 Land }; -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_GroundedEntryState")) enum class EALSGroundedEntryState : uint8 { None, Roll }; -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_HipsDirection")) enum class EALSHipsDirection : uint8 { F, @@ -149,7 +145,7 @@ enum class EALSHipsDirection : uint8 LB }; -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_MantleType")) enum class EALSMantleType : uint8 { HighMantle, @@ -157,7 +153,7 @@ enum class EALSMantleType : uint8 FallingCatch }; -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_MovementDirection")) enum class EALSMovementDirection : uint8 { Forward, @@ -166,7 +162,7 @@ enum class EALSMovementDirection : uint8 Backward }; -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (ScriptName = "ALS_SpawnType")) enum class EALSSpawnType : uint8 { Location, diff --git a/Source/ALSV4_CPP/Public/Library/ALSCharacterStructLibrary.h b/Source/ALSV4_CPP/Public/Library/ALSCharacterStructLibrary.h index 0fad3c84e..6c1983e75 100644 --- a/Source/ALSV4_CPP/Public/Library/ALSCharacterStructLibrary.h +++ b/Source/ALSV4_CPP/Public/Library/ALSCharacterStructLibrary.h @@ -1,15 +1,13 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once #include "CoreMinimal.h" #include "Engine/DataTable.h" +#include "PhysicalMaterials/PhysicalMaterial.h" +#include "Materials/MaterialInterface.h" #include "Library/ALSCharacterEnumLibrary.h" #include "ALSCharacterStructLibrary.generated.h" @@ -19,6 +17,9 @@ class UAnimMontage; class UAnimSequenceBase; class UCurveFloat; class UNiagaraSystem; +class UMaterialInterface; +class USoundBase; +class UPrimitiveComponent; USTRUCT(BlueprintType) struct FALSComponentAndTransform @@ -26,10 +27,10 @@ struct FALSComponentAndTransform GENERATED_BODY() UPROPERTY(EditAnywhere, Category = "Character Struct Library") - FTransform Transform; + FTransform Transform = FTransform::Identity; UPROPERTY(EditAnywhere, Category = "Character Struct Library") - class UPrimitiveComponent* Component = nullptr; + TObjectPtr Component = nullptr; }; USTRUCT(BlueprintType) @@ -41,7 +42,7 @@ struct FALSCameraSettings float TargetArmLength = 0.0f; UPROPERTY(EditAnywhere, Category = "Camera") - FVector SocketOffset; + FVector SocketOffset = FVector::ZeroVector; UPROPERTY(EditAnywhere, Category = "Camera") float LagSpeed = 0.0f; @@ -92,13 +93,13 @@ struct FALSMantleAsset GENERATED_BODY() UPROPERTY(EditAnywhere, Category = "Mantle System") - UAnimMontage* AnimMontage = nullptr; + TObjectPtr AnimMontage = nullptr; UPROPERTY(EditAnywhere, Category = "Mantle System") - UCurveVector* PositionCorrectionCurve = nullptr; + TObjectPtr PositionCorrectionCurve = nullptr; UPROPERTY(EditAnywhere, Category = "Mantle System") - FVector StartingOffset; + FVector StartingOffset = FVector::ZeroVector; UPROPERTY(EditAnywhere, Category = "Mantle System") float LowHeight = 0.0f; @@ -125,10 +126,10 @@ struct FALSMantleParams GENERATED_BODY() UPROPERTY(EditAnywhere, Category = "Mantle System") - UAnimMontage* AnimMontage = nullptr; + TObjectPtr AnimMontage = nullptr; UPROPERTY(EditAnywhere, Category = "Mantle System") - UCurveVector* PositionCorrectionCurve = nullptr; + TObjectPtr PositionCorrectionCurve = nullptr; UPROPERTY(EditAnywhere, Category = "Mantle System") float StartingPosition = 0.0f; @@ -137,7 +138,7 @@ struct FALSMantleParams float PlayRate = 0.0f; UPROPERTY(EditAnywhere, Category = "Mantle System") - FVector StartingOffset; + FVector StartingOffset = FVector::ZeroVector; }; USTRUCT(BlueprintType) @@ -176,10 +177,10 @@ struct FALSMovementSettings float SprintSpeed = 0.0f; UPROPERTY(EditAnywhere, Category = "Movement Settings") - UCurveVector* MovementCurve = nullptr; + TObjectPtr MovementCurve = nullptr; UPROPERTY(EditAnywhere, Category = "Movement Settings") - UCurveFloat* RotationRateCurve = nullptr; + TObjectPtr RotationRateCurve = nullptr; float GetSpeedForGait(const EALSGait Gait) const { @@ -230,10 +231,10 @@ struct FALSRotateInPlaceAsset GENERATED_BODY() UPROPERTY(EditAnywhere, Category = "Rotation System") - UAnimSequenceBase* Animation = nullptr; + TObjectPtr Animation = nullptr; UPROPERTY(EditAnywhere, Category = "Rotation System") - FName SlotName; + FName SlotName = NAME_None; UPROPERTY(EditAnywhere, Category = "Rotation System") float SlowTurnRate = 90.0f; @@ -254,56 +255,56 @@ struct FALSHitFX : public FTableRowBase GENERATED_BODY() UPROPERTY(EditAnywhere, Category = "Surface") - TEnumAsByte SurfaceType; + TEnumAsByte SurfaceType = EPhysicalSurface::SurfaceType_Default; UPROPERTY(EditAnywhere, Category = "Sound") - TSoftObjectPtr Sound; + TSoftObjectPtr Sound = nullptr; UPROPERTY(EditAnywhere, Category = "Sound") - EALSSpawnType SoundSpawnType; + EALSSpawnType SoundSpawnType = EALSSpawnType::Location; UPROPERTY(EditAnywhere, Category = "Sound", meta = (EditCondition = "SoundSpawnType == EALSSpawnType::Attached")) - TEnumAsByte SoundAttachmentType; + TEnumAsByte SoundAttachmentType = EAttachLocation::KeepRelativeOffset; UPROPERTY(EditAnywhere, Category = "Sound") - FVector SoundLocationOffset; + FVector SoundLocationOffset = FVector::ZeroVector; UPROPERTY(EditAnywhere, Category = "Sound") - FRotator SoundRotationOffset; + FRotator SoundRotationOffset = FRotator::ZeroRotator; UPROPERTY(EditAnywhere, Category = "Decal") - TSoftObjectPtr DecalMaterial; + TSoftObjectPtr DecalMaterial = nullptr; UPROPERTY(EditAnywhere, Category = "Decal") - EALSSpawnType DecalSpawnType; + EALSSpawnType DecalSpawnType = EALSSpawnType::Location; UPROPERTY(EditAnywhere, Category = "Decal", meta = (EditCondition = "DecalSpawnType == EALSSpawnType::Attached")) - TEnumAsByte DecalAttachmentType; + TEnumAsByte DecalAttachmentType = EAttachLocation::KeepRelativeOffset; UPROPERTY(EditAnywhere, Category = "Decal") float DecalLifeSpan = 10.0f; UPROPERTY(EditAnywhere, Category = "Decal") - FVector DecalSize; + FVector DecalSize = FVector::ZeroVector; UPROPERTY(EditAnywhere, Category = "Decal") - FVector DecalLocationOffset; + FVector DecalLocationOffset = FVector::ZeroVector; UPROPERTY(EditAnywhere, Category = "Decal") - FRotator DecalRotationOffset; + FRotator DecalRotationOffset = FRotator::ZeroRotator; UPROPERTY(EditAnywhere, Category = "Niagara") - TSoftObjectPtr NiagaraSystem; + TSoftObjectPtr NiagaraSystem = nullptr; UPROPERTY(EditAnywhere, Category = "Niagara") - EALSSpawnType NiagaraSpawnType; + EALSSpawnType NiagaraSpawnType = EALSSpawnType::Location; UPROPERTY(EditAnywhere, Category = "Niagara", meta = (EditCondition = "NiagaraSpawnType == EALSSpawnType::Attached")) - TEnumAsByte NiagaraAttachmentType; + TEnumAsByte NiagaraAttachmentType = EAttachLocation::KeepRelativeOffset; UPROPERTY(EditAnywhere, Category = "Niagara") - FVector NiagaraLocationOffset; + FVector NiagaraLocationOffset = FVector::ZeroVector; UPROPERTY(EditAnywhere, Category = "Niagara") - FRotator NiagaraRotationOffset; + FRotator NiagaraRotationOffset = FRotator::ZeroRotator; }; diff --git a/Source/ALSV4_CPP/Public/Library/ALSMathLibrary.h b/Source/ALSV4_CPP/Public/Library/ALSMathLibrary.h index 211f92b72..ce1b50613 100644 --- a/Source/ALSV4_CPP/Public/Library/ALSMathLibrary.h +++ b/Source/ALSV4_CPP/Public/Library/ALSMathLibrary.h @@ -1,16 +1,14 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Doğa Can Yanıkoğlu -// Contributors: - +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once -#include "ALSCharacterEnumLibrary.h" #include "CoreMinimal.h" +#include "ALSCharacterEnumLibrary.h" +#include "Engine/World.h" +#include "Kismet/KismetSystemLibrary.h" #include "Library/ALSCharacterStructLibrary.h" + #include "ALSMathLibrary.generated.h" class UCapsuleComponent; @@ -27,17 +25,15 @@ class ALSV4_CPP_API UALSMathLibrary : public UBlueprintFunctionLibrary UFUNCTION(BlueprintCallable, Category = "ALS|Math Utils") static FTransform MantleComponentLocalToWorld(const FALSComponentAndTransform& CompAndTransform); - static TPair FixDiagonalGamepadValues(float X, float Y); - UFUNCTION(BlueprintCallable, Category = "ALS|Math Utils") - static FTransform TransfromSub(const FTransform& T1, const FTransform& T2) + static FTransform TransformSub(const FTransform& T1, const FTransform& T2) { return FTransform(T1.GetRotation().Rotator() - T2.GetRotation().Rotator(), T1.GetLocation() - T2.GetLocation(), T1.GetScale3D() - T2.GetScale3D()); } UFUNCTION(BlueprintCallable, Category = "ALS|Math Utils") - static FTransform TransfromAdd(const FTransform& T1, const FTransform& T2) + static FTransform TransformAdd(const FTransform& T1, const FTransform& T2) { return FTransform(T1.GetRotation().Rotator() + T2.GetRotation().Rotator(), T1.GetLocation() + T2.GetLocation(), T1.GetScale3D() + T2.GetScale3D()); @@ -51,7 +47,7 @@ class ALSV4_CPP_API UALSMathLibrary : public UBlueprintFunctionLibrary UFUNCTION(BlueprintCallable, Category = "ALS|Math Utils") static bool CapsuleHasRoomCheck(UCapsuleComponent* Capsule, FVector TargetLocation, float HeightOffset, - float RadiusOffset); + float RadiusOffset, EDrawDebugTrace::Type DebugType = EDrawDebugTrace::Type::None, bool DrawDebugTrace = false); UFUNCTION(BlueprintCallable, Category = "ALS|Math Utils") static bool AngleInRange(float Angle, float MinAngle, float MaxAngle, float Buffer, bool IncreaseBuffer); diff --git a/Source/ALSV4_CPP/Public/Library/ALSStructEnumLibrary.h b/Source/ALSV4_CPP/Public/Library/ALSStructEnumLibrary.h index 054fa40c6..16a3b8ed5 100644 --- a/Source/ALSV4_CPP/Public/Library/ALSStructEnumLibrary.h +++ b/Source/ALSV4_CPP/Public/Library/ALSStructEnumLibrary.h @@ -1,9 +1,5 @@ -// Project: Advanced Locomotion System V4 on C++ -// Copyright: Copyright (C) 2021 Doğa Can Yanıkoğlu -// License: MIT License (http://www.opensource.org/licenses/mit-license.php) -// Source Code: https://github.com/dyanikoglu/ALSV4_CPP -// Original Author: Jens Bjarne Myhre -// Contributors: Doğa Can Yanıkoğlu +// Copyright: Copyright (C) 2022 Doğa Can Yanıkoğlu +// Source Code: https://github.com/dyanikoglu/ALS-Community #pragma once