From 93de3681f0fec39003229d91ba197367f86bc225 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 18 Nov 2020 00:11:03 +0100 Subject: [PATCH] Animations! Animations for walking, running, jumping while running Improved ground detection Fixed some character functionality not working above a certain speed --- Assets/Animations.meta | 8 + Assets/Animations/Character.controller | 373 ++++++++++++++++++ Assets/Animations/Character.controller.meta | 8 + Assets/Animations/CharacterFall.anim | 77 ++++ Assets/Animations/CharacterFall.anim.meta | 8 + Assets/Animations/CharacterJump.anim | 140 +++++++ Assets/Animations/CharacterJump.anim.meta | 8 + Assets/Animations/CharacterRun.anim | 85 ++++ Assets/Animations/CharacterRun.anim.meta | 8 + Assets/Animations/CharacterStand.anim | 73 ++++ Assets/Animations/CharacterStand.anim.meta | 8 + Assets/Animations/CharacterWalk.anim | 148 +++++++ Assets/Animations/CharacterWalk.anim.meta | 8 + Assets/Prefabs/Enemy.prefab | 38 +- .../Scenes/{SampleScene.unity => Main.unity} | 73 +++- ...SampleScene.unity.meta => Main.unity.meta} | 0 Assets/Scripts/CharacterControllerBase.cs | 9 +- Assets/Scripts/EnemySpawner.cs | 2 +- Assets/Scripts/OwnCharacterController.cs | 42 +- ProjectSettings/TagManager.asset | 2 +- 20 files changed, 1100 insertions(+), 18 deletions(-) create mode 100644 Assets/Animations.meta create mode 100644 Assets/Animations/Character.controller create mode 100644 Assets/Animations/Character.controller.meta create mode 100644 Assets/Animations/CharacterFall.anim create mode 100644 Assets/Animations/CharacterFall.anim.meta create mode 100644 Assets/Animations/CharacterJump.anim create mode 100644 Assets/Animations/CharacterJump.anim.meta create mode 100644 Assets/Animations/CharacterRun.anim create mode 100644 Assets/Animations/CharacterRun.anim.meta create mode 100644 Assets/Animations/CharacterStand.anim create mode 100644 Assets/Animations/CharacterStand.anim.meta create mode 100644 Assets/Animations/CharacterWalk.anim create mode 100644 Assets/Animations/CharacterWalk.anim.meta rename Assets/Scenes/{SampleScene.unity => Main.unity} (95%) rename Assets/Scenes/{SampleScene.unity.meta => Main.unity.meta} (100%) diff --git a/Assets/Animations.meta b/Assets/Animations.meta new file mode 100644 index 0000000..d3f3a7c --- /dev/null +++ b/Assets/Animations.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 38ceae954c414f427ae4fa920b225227 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Animations/Character.controller b/Assets/Animations/Character.controller new file mode 100644 index 0000000..16daa9f --- /dev/null +++ b/Assets/Animations/Character.controller @@ -0,0 +1,373 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1101 &-8987728897907739601 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 4 + m_ConditionEvent: Speed + m_EventTreshold: 0.1 + - m_ConditionMode: 6 + m_ConditionEvent: Jump + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 2915947465038908738} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0 + m_ExitTime: 0 + m_HasExitTime: 0 + m_HasFixedDuration: 0 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 0 +--- !u!1101 &-4624505121643448120 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 3 + m_ConditionEvent: Speed + m_EventTreshold: 0.1 + - m_ConditionMode: 2 + m_ConditionEvent: Sprint + m_EventTreshold: 0 + - m_ConditionMode: 6 + m_ConditionEvent: Jump + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -1544678512520658519} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0 + m_ExitTime: 0 + m_HasExitTime: 0 + m_HasFixedDuration: 0 + m_InterruptionSource: 0 + m_OrderedInterruption: 0 + m_CanTransitionToSelf: 0 +--- !u!1102 &-1640697823006375366 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterFall + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 8f5a80ecc7eac151ea33800135ba8077, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &-1544678512520658519 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterWalk + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: c0434a9d917dba6a88867cea38f003a8, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1101 &-1163576790731296724 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 3 + m_ConditionEvent: Speed + m_EventTreshold: 0.9 + - m_ConditionMode: 1 + m_ConditionEvent: Sprint + m_EventTreshold: 0 + - m_ConditionMode: 6 + m_ConditionEvent: Jump + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 1306503613525126779} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0 + m_ExitTime: 0 + m_HasExitTime: 0 + m_HasFixedDuration: 0 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 0 +--- !u!91 &9100000 +AnimatorController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Character + serializedVersion: 5 + m_AnimatorParameters: + - m_Name: Speed + m_Type: 1 + m_DefaultFloat: 0 + m_DefaultInt: 0 + m_DefaultBool: 0 + m_Controller: {fileID: 9100000} + - m_Name: Sprint + m_Type: 4 + m_DefaultFloat: 0 + m_DefaultInt: 0 + m_DefaultBool: 0 + m_Controller: {fileID: 9100000} + - m_Name: Jump + m_Type: 3 + m_DefaultFloat: 0 + m_DefaultInt: 0 + m_DefaultBool: 0 + m_Controller: {fileID: 9100000} + m_AnimatorLayers: + - serializedVersion: 5 + m_Name: Base Layer + m_StateMachine: {fileID: 723122302859164095} + m_Mask: {fileID: 0} + m_Motions: [] + m_Behaviours: [] + m_BlendingMode: 0 + m_SyncedLayerIndex: -1 + m_DefaultWeight: 0 + m_IKPass: 0 + m_SyncedLayerAffectsTiming: 0 + m_Controller: {fileID: 9100000} +--- !u!1107 &723122302859164095 +AnimatorStateMachine: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Base Layer + m_ChildStates: + - serializedVersion: 1 + m_State: {fileID: 2915947465038908738} + m_Position: {x: 260, y: 140, z: 0} + - serializedVersion: 1 + m_State: {fileID: -1544678512520658519} + m_Position: {x: 520, y: -10, z: 0} + - serializedVersion: 1 + m_State: {fileID: 1306503613525126779} + m_Position: {x: 270, y: -90, z: 0} + - serializedVersion: 1 + m_State: {fileID: 7822183342188573683} + m_Position: {x: 470, y: 80, z: 0} + - serializedVersion: 1 + m_State: {fileID: -1640697823006375366} + m_Position: {x: 530, y: 160, z: 0} + m_ChildStateMachines: [] + m_AnyStateTransitions: + - {fileID: -4624505121643448120} + - {fileID: -8987728897907739601} + - {fileID: -1163576790731296724} + - {fileID: 4827319619884786487} + m_EntryTransitions: [] + m_StateMachineTransitions: {} + m_StateMachineBehaviours: [] + m_AnyStatePosition: {x: 50, y: 20, z: 0} + m_EntryPosition: {x: 50, y: 120, z: 0} + m_ExitPosition: {x: 800, y: 120, z: 0} + m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} + m_DefaultState: {fileID: 2915947465038908738} +--- !u!1102 &1306503613525126779 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterRun + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 6ef74ee92b1d2aeeb9ba73f040248c86, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &2915947465038908738 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterStand + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 9932b64dda35ac26baf8d9a71ae6fa5c, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1101 &4827319619884786487 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 6 + m_ConditionEvent: Jump + m_EventTreshold: 1 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 7822183342188573683} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 0 + m_HasFixedDuration: 0 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 0 +--- !u!1101 &5550797005891240585 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: [] + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 7822183342188573683} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.25 + m_TransitionOffset: 0 + m_ExitTime: 0.75409836 + m_HasExitTime: 1 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 +--- !u!1101 &7778810051654835894 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 6 + m_ConditionEvent: Jump + m_EventTreshold: 2 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -1640697823006375366} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0 + m_ExitTime: 0.75409836 + m_HasExitTime: 0 + m_HasFixedDuration: 0 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 +--- !u!1102 &7822183342188573683 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterJump + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: + - {fileID: 7778810051654835894} + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: f6cafb9f28dbf71caad2b1701d863a18, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: diff --git a/Assets/Animations/Character.controller.meta b/Assets/Animations/Character.controller.meta new file mode 100644 index 0000000..f652439 --- /dev/null +++ b/Assets/Animations/Character.controller.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8a45d79eff56ac9fe9c8c50b3318a6ed +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Animations/CharacterFall.anim b/Assets/Animations/CharacterFall.anim new file mode 100644 index 0000000..bb16bff --- /dev/null +++ b/Assets/Animations/CharacterFall.anim @@ -0,0 +1,77 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterFall + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: [] + m_PPtrCurves: + - curve: + - time: 0 + value: {fileID: 3361131043089554334, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.16666667 + value: {fileID: -8789370896416366076, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.33333334 + value: {fileID: 5728794044653291647, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + attribute: m_Sprite + path: + classID: 212 + script: {fileID: 0} + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: + - serializedVersion: 2 + path: 0 + attribute: 0 + script: {fileID: 0} + typeID: 212 + customType: 23 + isPPtrCurve: 1 + pptrCurveMapping: + - {fileID: 3361131043089554334, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: -8789370896416366076, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: 5728794044653291647, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 0.35000002 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 0 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: [] + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Assets/Animations/CharacterFall.anim.meta b/Assets/Animations/CharacterFall.anim.meta new file mode 100644 index 0000000..2f434da --- /dev/null +++ b/Assets/Animations/CharacterFall.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8f5a80ecc7eac151ea33800135ba8077 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Animations/CharacterJump.anim b/Assets/Animations/CharacterJump.anim new file mode 100644 index 0000000..50a5e6c --- /dev/null +++ b/Assets/Animations/CharacterJump.anim @@ -0,0 +1,140 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterJump + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 0.33333334 + value: 0 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_IsActive + path: Gun + classID: 1 + script: {fileID: 0} + m_PPtrCurves: + - curve: + - time: 0 + value: {fileID: 8959041838961795847, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.16666667 + value: {fileID: -2258061119048845259, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.33333334 + value: {fileID: 3361131043089554334, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + attribute: m_Sprite + path: + classID: 212 + script: {fileID: 0} + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: + - serializedVersion: 2 + path: 1926661051 + attribute: 2086281974 + script: {fileID: 0} + typeID: 1 + customType: 0 + isPPtrCurve: 0 + - serializedVersion: 2 + path: 0 + attribute: 0 + script: {fileID: 0} + typeID: 212 + customType: 23 + isPPtrCurve: 1 + pptrCurveMapping: + - {fileID: 8959041838961795847, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: -2258061119048845259, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: 3361131043089554334, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 0.35000002 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 0 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 0.33333334 + value: 0 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_IsActive + path: Gun + classID: 1 + script: {fileID: 0} + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Assets/Animations/CharacterJump.anim.meta b/Assets/Animations/CharacterJump.anim.meta new file mode 100644 index 0000000..f216d96 --- /dev/null +++ b/Assets/Animations/CharacterJump.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f6cafb9f28dbf71caad2b1701d863a18 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Animations/CharacterRun.anim b/Assets/Animations/CharacterRun.anim new file mode 100644 index 0000000..e278c5e --- /dev/null +++ b/Assets/Animations/CharacterRun.anim @@ -0,0 +1,85 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterRun + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: [] + m_PPtrCurves: + - curve: + - time: 0 + value: {fileID: 8959041838961795847, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.25 + value: {fileID: -8623413058668782668, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.5 + value: {fileID: 5728794044653291647, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.75 + value: {fileID: -2258061119048845259, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 1 + value: {fileID: 8959041838961795847, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + attribute: m_Sprite + path: + classID: 212 + script: {fileID: 0} + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: + - serializedVersion: 2 + path: 0 + attribute: 0 + script: {fileID: 0} + typeID: 212 + customType: 23 + isPPtrCurve: 1 + pptrCurveMapping: + - {fileID: 8959041838961795847, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: -8623413058668782668, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: 5728794044653291647, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: -2258061119048845259, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: 8959041838961795847, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 1.0166667 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 1 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: [] + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Assets/Animations/CharacterRun.anim.meta b/Assets/Animations/CharacterRun.anim.meta new file mode 100644 index 0000000..f497053 --- /dev/null +++ b/Assets/Animations/CharacterRun.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6ef74ee92b1d2aeeb9ba73f040248c86 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Animations/CharacterStand.anim b/Assets/Animations/CharacterStand.anim new file mode 100644 index 0000000..a2be5e0 --- /dev/null +++ b/Assets/Animations/CharacterStand.anim @@ -0,0 +1,73 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterStand + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: [] + m_PPtrCurves: + - curve: + - time: 0 + value: {fileID: 6185353665997233981, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 1 + value: {fileID: 6185353665997233981, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + attribute: m_Sprite + path: + classID: 212 + script: {fileID: 0} + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: + - serializedVersion: 2 + path: 0 + attribute: 0 + script: {fileID: 0} + typeID: 212 + customType: 23 + isPPtrCurve: 1 + pptrCurveMapping: + - {fileID: 6185353665997233981, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: 6185353665997233981, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 1.0166667 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 1 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: [] + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Assets/Animations/CharacterStand.anim.meta b/Assets/Animations/CharacterStand.anim.meta new file mode 100644 index 0000000..7000c14 --- /dev/null +++ b/Assets/Animations/CharacterStand.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9932b64dda35ac26baf8d9a71ae6fa5c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Animations/CharacterWalk.anim b/Assets/Animations/CharacterWalk.anim new file mode 100644 index 0000000..f9add97 --- /dev/null +++ b/Assets/Animations/CharacterWalk.anim @@ -0,0 +1,148 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: CharacterWalk + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: [] + m_FloatCurves: + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_IsActive + path: Gun + classID: 1 + script: {fileID: 0} + m_PPtrCurves: + - curve: + - time: 0 + value: {fileID: -1989377262933277898, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.25 + value: {fileID: -6618872083037343320, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.5 + value: {fileID: -3982056006877205448, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 0.75 + value: {fileID: 8154732895160588515, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + - time: 1 + value: {fileID: -1989377262933277898, guid: 22df4be82d91637658b965dd24a4a591, + type: 3} + attribute: m_Sprite + path: + classID: 212 + script: {fileID: 0} + m_SampleRate: 60 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: + - serializedVersion: 2 + path: 1926661051 + attribute: 2086281974 + script: {fileID: 0} + typeID: 1 + customType: 0 + isPPtrCurve: 0 + - serializedVersion: 2 + path: 0 + attribute: 0 + script: {fileID: 0} + typeID: 212 + customType: 23 + isPPtrCurve: 1 + pptrCurveMapping: + - {fileID: -1989377262933277898, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: -6618872083037343320, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: -3982056006877205448, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: 8154732895160588515, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + - {fileID: -1989377262933277898, guid: 22df4be82d91637658b965dd24a4a591, type: 3} + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 1.0166667 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 1 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: Infinity + outSlope: Infinity + tangentMode: 103 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_IsActive + path: Gun + classID: 1 + script: {fileID: 0} + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_Events: [] diff --git a/Assets/Animations/CharacterWalk.anim.meta b/Assets/Animations/CharacterWalk.anim.meta new file mode 100644 index 0000000..9dd30d4 --- /dev/null +++ b/Assets/Animations/CharacterWalk.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c0434a9d917dba6a88867cea38f003a8 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Enemy.prefab b/Assets/Prefabs/Enemy.prefab index d4dc940..1af2a18 100644 --- a/Assets/Prefabs/Enemy.prefab +++ b/Assets/Prefabs/Enemy.prefab @@ -1,5 +1,35 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &4407407046900251487 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1529445790525209946} + m_Layer: 0 + m_Name: Foot + m_TagString: Untagged + m_Icon: {fileID: 4422084297763085224, guid: 0000000000000000d000000000000000, type: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1529445790525209946 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4407407046900251487} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.049, y: -0.241, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 7250562544566202698} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7250562544566202694 GameObject: m_ObjectHideFlags: 0 @@ -30,7 +60,8 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: -0.31, y: 4.27, z: 0} m_LocalScale: {x: -1, y: 1, z: 1} - m_Children: [] + m_Children: + - {fileID: 1529445790525209946} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -143,6 +174,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a86eb57291c5f566d8b1cb9f87a029d9, type: 3} m_Name: m_EditorClassIdentifier: + foot: {fileID: 1529445790525209946} + groundRadius: 0.1 + groundMask: + serializedVersion: 2 + m_Bits: 256 target: {fileID: 0} speed: 8 flyForce: 30 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/Main.unity similarity index 95% rename from Assets/Scenes/SampleScene.unity rename to Assets/Scenes/Main.unity index 31e3834..acd555d 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/Main.unity @@ -201,7 +201,7 @@ GameObject: - component: {fileID: 407879045} - component: {fileID: 407879044} - component: {fileID: 407879046} - m_Layer: 0 + m_Layer: 8 m_Name: PlatformMid m_TagString: Ground m_Icon: {fileID: 0} @@ -309,7 +309,7 @@ GameObject: - component: {fileID: 413955008} - component: {fileID: 413955007} - component: {fileID: 413955009} - m_Layer: 0 + m_Layer: 8 m_Name: PlatformRight m_TagString: Ground m_Icon: {fileID: 0} @@ -405,7 +405,8 @@ PolygonCollider2D: m_AutoTiling: 0 m_Points: m_Paths: - - - {x: -0.35, y: 0.35} + - - {x: -0.34868273, y: 0.35010514} + - {x: -0.34908652, y: 0.34994364} - {x: -0.35, y: -0.35} - {x: -0.021993905, y: -0.2905682} - {x: 0.22573361, y: -0.16113642} @@ -539,7 +540,7 @@ GameObject: - component: {fileID: 887921231} - component: {fileID: 887921230} - component: {fileID: 887921232} - m_Layer: 0 + m_Layer: 8 m_Name: PlatformLeft m_TagString: Ground m_Icon: {fileID: 0} @@ -642,7 +643,7 @@ PolygonCollider2D: - {x: -0.15077958, y: -0.21121931} - {x: 0.031678874, y: -0.2983211} - {x: 0.35, y: -0.35} - - {x: 0.35, y: 0.35} + - {x: 0.3502799, y: 0.34996805} --- !u!1 &996257474 GameObject: m_ObjectHideFlags: 0 @@ -756,6 +757,36 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: smoothing: 1 +--- !u!1 &1005132794 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1005132795} + m_Layer: 0 + m_Name: Foot + m_TagString: Untagged + m_Icon: {fileID: 4422084297763085224, guid: 0000000000000000d000000000000000, type: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1005132795 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1005132794} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.061, y: -0.221, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 2053847422} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1043406433 GameObject: m_ObjectHideFlags: 0 @@ -1126,7 +1157,7 @@ GameObject: - component: {fileID: 1508769556} - component: {fileID: 1508769557} - component: {fileID: 1508769558} - m_Layer: 0 + m_Layer: 8 m_Name: Ground m_TagString: Ground m_Icon: {fileID: 0} @@ -1381,6 +1412,7 @@ GameObject: - component: {fileID: 2053847423} - component: {fileID: 2053847425} - component: {fileID: 2053847426} + - component: {fileID: 2053847427} m_Layer: 0 m_Name: Character m_TagString: Player @@ -1451,6 +1483,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1811013770} + - {fileID: 1005132795} m_Father: {fileID: 0} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1513,9 +1546,14 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 216ec793de06a4ac7a9767782a179419, type: 3} m_Name: m_EditorClassIdentifier: + foot: {fileID: 1005132795} + groundRadius: 0.1 + groundMask: + serializedVersion: 2 + m_Bits: 256 jumpForce: 5 - movementSpeed: 5 - sprintSpeed: 15 + movementSpeed: 2 + sprintSpeed: 1.5 platformSpawner: {fileID: 219260673} --- !u!114 &2053847426 MonoBehaviour: @@ -1531,3 +1569,22 @@ MonoBehaviour: m_EditorClassIdentifier: prefab: {fileID: 6006275050469676560, guid: 7debf3c35b28387fdbec1c1c9942afae, type: 3} firePoint: {fileID: 1043406434} +--- !u!95 &2053847427 +Animator: + serializedVersion: 3 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2053847420} + m_Enabled: 1 + m_Avatar: {fileID: 0} + m_Controller: {fileID: 9100000, guid: 8a45d79eff56ac9fe9c8c50b3318a6ed, type: 2} + m_CullingMode: 0 + m_UpdateMode: 0 + m_ApplyRootMotion: 0 + m_LinearVelocityBlending: 0 + m_WarningMessage: + m_HasTransformHierarchy: 1 + m_AllowConstantClipSamplingOptimization: 1 + m_KeepAnimatorControllerStateOnDisable: 0 diff --git a/Assets/Scenes/SampleScene.unity.meta b/Assets/Scenes/Main.unity.meta similarity index 100% rename from Assets/Scenes/SampleScene.unity.meta rename to Assets/Scenes/Main.unity.meta diff --git a/Assets/Scripts/CharacterControllerBase.cs b/Assets/Scripts/CharacterControllerBase.cs index 40c796e..1bf925b 100644 --- a/Assets/Scripts/CharacterControllerBase.cs +++ b/Assets/Scripts/CharacterControllerBase.cs @@ -5,11 +5,14 @@ using UnityEngine; public abstract class CharacterControllerBase : MonoBehaviour { protected Rigidbody2D _rb; + + public Transform foot; + public float groundRadius; + public LayerMask groundMask; public bool IsOnGround(string groundName = "") { - var res = new List(); - _rb.OverlapCollider(new ContactFilter2D(), res); - return res.Any(col => col.CompareTag("Ground") && (groundName.Length == 0 || col.name.StartsWith(groundName))); + var collider = Physics2D.OverlapCircle(foot.position, groundRadius, groundMask); + return collider && (groundName.Length == 0 || collider.name.StartsWith(groundName)); } } \ No newline at end of file diff --git a/Assets/Scripts/EnemySpawner.cs b/Assets/Scripts/EnemySpawner.cs index 767f9fc..4b5b6a6 100644 --- a/Assets/Scripts/EnemySpawner.cs +++ b/Assets/Scripts/EnemySpawner.cs @@ -26,7 +26,7 @@ public class EnemySpawner : MonoBehaviour private void FixedUpdate() { //int timeMultiplier = _spawner.maxLevel - _spawner.Level; - int countMultiplier = _spawner.Level; + int countMultiplier = _spawner.Level + 1; if (Time.fixedTime - _lastSpawn > timeBetweenSpawns && _random.Next(2) == 1) { short count = (short) _random.Next(maxEnemyCount * countMultiplier); diff --git a/Assets/Scripts/OwnCharacterController.cs b/Assets/Scripts/OwnCharacterController.cs index 0121070..a510ddf 100644 --- a/Assets/Scripts/OwnCharacterController.cs +++ b/Assets/Scripts/OwnCharacterController.cs @@ -17,12 +17,18 @@ public class OwnCharacterController : CharacterControllerBase private readonly Random _random = new Random(); private readonly List _checkpointPosList = new List(); private Vector3 _checkpointPos; + private Animator _animator; + private static readonly int Speed = Animator.StringToHash("Speed"); + private static readonly int Jump = Animator.StringToHash("Jump"); + private static readonly int Sprint = Animator.StringToHash("Sprint"); + private JumpStatus _jumpStatus = JumpStatus.None; // Start is called before the first frame update void Start() { _rb = GetComponent(); _spawnPos = transform.position; + _animator = GetComponent(); } // Update is called once per frame @@ -30,8 +36,6 @@ public class OwnCharacterController : CharacterControllerBase { if (platformSpawner.ShouldRespawn(transform, this)) Respawn(); - if (Mathf.Abs(_rb.velocity.x) > 3) - return; float input = Input.GetAxis("Horizontal"); var tr = transform; if (input < 0 && tr.localScale.x > 0 @@ -44,10 +48,30 @@ public class OwnCharacterController : CharacterControllerBase if (Input.GetButton("Fire3")) input *= sprintSpeed; - _rb.AddForce(new Vector2(input * movementSpeed, 0)); + + if (Mathf.Abs(_rb.velocity.x) <= 3) + _rb.velocity += new Vector2(input * movementSpeed, 0); if (Input.GetButtonDown("Jump") && IsOnGround()) - _rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse); + { + //_rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse); + _rb.velocity += new Vector2(0, jumpForce); + if (Input.GetButton("Fire3")) //Csak akkor animálja az ugrást, ha fut közben + { + _jumpStatus = JumpStatus.Up; + _animator.SetInteger(Jump, (int) _jumpStatus); + } + } + else if (_jumpStatus == JumpStatus.Up && _rb.velocity.y <= 0) + { + _jumpStatus = JumpStatus.Down; + _animator.SetInteger(Jump, (int) _jumpStatus); + } + else if (_jumpStatus == JumpStatus.Down && Math.Abs(_rb.velocity.y) <= 0.001f) + { + _jumpStatus = JumpStatus.None; + _animator.SetInteger(Jump, (int) _jumpStatus); + } if (_checkpointPos.x > 0 && (tr.position - _checkpointPos).magnitude < 2f) { @@ -55,6 +79,9 @@ public class OwnCharacterController : CharacterControllerBase _checkpointPosList.RemoveAt(0); _checkpointPos = _checkpointPosList.Count > 0 ? _checkpointPosList[0] : Vector3.zero; } + + _animator.SetFloat(Speed, Math.Abs(_rb.velocity.x)); + _animator.SetBool(Sprint, Input.GetButton("Fire3")); } public void Hit() @@ -76,4 +103,11 @@ public class OwnCharacterController : CharacterControllerBase _checkpointPosList.Add(pos); if (_checkpointPos.x <= 0) _checkpointPos = _checkpointPosList[0]; } + + enum JumpStatus + { + None, + Up, + Down + } } \ No newline at end of file diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index f1da479..566d213 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -16,7 +16,7 @@ TagManager: - UI - - - - + - Ground - - -