From 0859e4b36c77c00df61c4755e8fc4a441f069134 Mon Sep 17 00:00:00 2001 From: BuyMyMojo Date: Sun, 26 Feb 2023 02:09:56 +1100 Subject: [PATCH] Finish my animations --- Assets/AnimationControllers.meta | 8 +++ .../MyPlayerAnimator.controller | 68 +++++++++++++++++-- .../MyPlayerAnimator.controller.meta | 0 Assets/Animations.meta | 8 +++ Assets/{ => Animations}/Idle.anim | 0 Assets/{ => Animations}/Idle.anim.meta | 0 Assets/{ => Animations}/Walk.anim | 34 +++++----- Assets/{ => Animations}/Walk.anim.meta | 0 Assets/Scenes/GaneScene.unity | 17 +++++ Assets/Scripts/Player.cs | 10 ++- Assets/Scripts/PlayerAnimator.cs | 23 +++++++ Assets/Scripts/PlayerAnimator.cs.meta | 11 +++ 12 files changed, 156 insertions(+), 23 deletions(-) create mode 100644 Assets/AnimationControllers.meta rename Assets/{ => AnimationControllers}/MyPlayerAnimator.controller (62%) rename Assets/{ => AnimationControllers}/MyPlayerAnimator.controller.meta (100%) create mode 100644 Assets/Animations.meta rename Assets/{ => Animations}/Idle.anim (100%) rename Assets/{ => Animations}/Idle.anim.meta (100%) rename Assets/{ => Animations}/Walk.anim (95%) rename Assets/{ => Animations}/Walk.anim.meta (100%) create mode 100644 Assets/Scripts/PlayerAnimator.cs create mode 100644 Assets/Scripts/PlayerAnimator.cs.meta diff --git a/Assets/AnimationControllers.meta b/Assets/AnimationControllers.meta new file mode 100644 index 0000000..b7d9306 --- /dev/null +++ b/Assets/AnimationControllers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c74438f7d0693d94ab988a019e529d1e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MyPlayerAnimator.controller b/Assets/AnimationControllers/MyPlayerAnimator.controller similarity index 62% rename from Assets/MyPlayerAnimator.controller rename to Assets/AnimationControllers/MyPlayerAnimator.controller index 297f5c3..e37c8a0 100644 --- a/Assets/MyPlayerAnimator.controller +++ b/Assets/AnimationControllers/MyPlayerAnimator.controller @@ -1,5 +1,30 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1101 &-8942769352569325474 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 1 + m_ConditionEvent: IsWalking + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -8110582496927358665} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.25 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!1102 &-8110582496927358665 AnimatorState: serializedVersion: 6 @@ -10,7 +35,8 @@ AnimatorState: m_Name: Walk m_Speed: 1 m_CycleOffset: 0 - m_Transitions: [] + m_Transitions: + - {fileID: -1141462849142485002} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 @@ -26,6 +52,31 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1101 &-1141462849142485002 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 2 + m_ConditionEvent: IsWalking + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 8537115090425330708} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.14166665 + m_TransitionOffset: 0 + m_ExitTime: 0.57142866 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!91 &9100000 AnimatorController: m_ObjectHideFlags: 0 @@ -34,7 +85,13 @@ AnimatorController: m_PrefabAsset: {fileID: 0} m_Name: MyPlayerAnimator serializedVersion: 5 - m_AnimatorParameters: [] + m_AnimatorParameters: + - m_Name: IsWalking + m_Type: 4 + m_DefaultFloat: 0 + m_DefaultInt: 0 + m_DefaultBool: 0 + m_Controller: {fileID: 0} m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer @@ -59,10 +116,10 @@ AnimatorStateMachine: m_ChildStates: - serializedVersion: 1 m_State: {fileID: 8537115090425330708} - m_Position: {x: 340, y: 150, z: 0} + m_Position: {x: 270, y: 170, z: 0} - serializedVersion: 1 m_State: {fileID: -8110582496927358665} - m_Position: {x: 440, y: -110, z: 0} + m_Position: {x: 540, y: 170, z: 0} m_ChildStateMachines: [] m_AnyStateTransitions: [] m_EntryTransitions: [] @@ -83,7 +140,8 @@ AnimatorState: m_Name: Idle m_Speed: 1 m_CycleOffset: 0 - m_Transitions: [] + m_Transitions: + - {fileID: -8942769352569325474} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 diff --git a/Assets/MyPlayerAnimator.controller.meta b/Assets/AnimationControllers/MyPlayerAnimator.controller.meta similarity index 100% rename from Assets/MyPlayerAnimator.controller.meta rename to Assets/AnimationControllers/MyPlayerAnimator.controller.meta diff --git a/Assets/Animations.meta b/Assets/Animations.meta new file mode 100644 index 0000000..7a3876b --- /dev/null +++ b/Assets/Animations.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4cc8ef723b2928d45a19519c93a37ccd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Idle.anim b/Assets/Animations/Idle.anim similarity index 100% rename from Assets/Idle.anim rename to Assets/Animations/Idle.anim diff --git a/Assets/Idle.anim.meta b/Assets/Animations/Idle.anim.meta similarity index 100% rename from Assets/Idle.anim.meta rename to Assets/Animations/Idle.anim.meta diff --git a/Assets/Walk.anim b/Assets/Animations/Walk.anim similarity index 95% rename from Assets/Walk.anim rename to Assets/Animations/Walk.anim index 09711fe..0a7636e 100644 --- a/Assets/Walk.anim +++ b/Assets/Animations/Walk.anim @@ -28,7 +28,7 @@ AnimationClip: inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - serializedVersion: 3 - time: 0.3 + time: 0.16666667 value: {x: 0, y: 1.659, z: 0} inSlope: {x: 0, y: 0, z: 0} outSlope: {x: 0, y: 0, z: 0} @@ -37,7 +37,7 @@ AnimationClip: inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - serializedVersion: 3 - time: 0.5833333 + time: 0.33333334 value: {x: 0, y: 1.521, z: 0} inSlope: {x: 0, y: 0, z: 0} outSlope: {x: 0, y: 0, z: 0} @@ -62,7 +62,7 @@ AnimationClip: inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - serializedVersion: 3 - time: 0.25 + time: 0.15 value: {x: 0, y: 0.771, z: 0} inSlope: {x: 0, y: 0, z: 0} outSlope: {x: 0, y: 0, z: 0} @@ -71,7 +71,7 @@ AnimationClip: inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} - serializedVersion: 3 - time: 0.5833333 + time: 0.33333334 value: {x: 0, y: 0.65, z: 0} inSlope: {x: 0, y: 0, z: 0} outSlope: {x: 0, y: 0, z: 0} @@ -117,7 +117,7 @@ AnimationClip: m_AdditiveReferencePoseClip: {fileID: 0} m_AdditiveReferencePoseTime: 0 m_StartTime: 0 - m_StopTime: 0.5833333 + m_StopTime: 0.33333334 m_OrientationOffsetY: 0 m_Level: 0 m_CycleOffset: 0 @@ -147,7 +147,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.3 + time: 0.16666667 value: 0 inSlope: 0 outSlope: 0 @@ -156,7 +156,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.5833333 + time: 0.33333334 value: 0 inSlope: 0 outSlope: 0 @@ -186,7 +186,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.3 + time: 0.16666667 value: 1.659 inSlope: 0 outSlope: 0 @@ -195,7 +195,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.5833333 + time: 0.33333334 value: 1.521 inSlope: 0 outSlope: 0 @@ -225,7 +225,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.3 + time: 0.16666667 value: 0 inSlope: 0 outSlope: 0 @@ -234,7 +234,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.5833333 + time: 0.33333334 value: 0 inSlope: 0 outSlope: 0 @@ -264,7 +264,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.25 + time: 0.15 value: 0 inSlope: 0 outSlope: 0 @@ -273,7 +273,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.5833333 + time: 0.33333334 value: 0 inSlope: 0 outSlope: 0 @@ -303,7 +303,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.25 + time: 0.15 value: 0.771 inSlope: 0 outSlope: 0 @@ -312,7 +312,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.5833333 + time: 0.33333334 value: 0.65 inSlope: 0 outSlope: 0 @@ -342,7 +342,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.25 + time: 0.15 value: 0 inSlope: 0 outSlope: 0 @@ -351,7 +351,7 @@ AnimationClip: inWeight: 0.33333334 outWeight: 0.33333334 - serializedVersion: 3 - time: 0.5833333 + time: 0.33333334 value: 0 inSlope: 0 outSlope: 0 diff --git a/Assets/Walk.anim.meta b/Assets/Animations/Walk.anim.meta similarity index 100% rename from Assets/Walk.anim.meta rename to Assets/Animations/Walk.anim.meta diff --git a/Assets/Scenes/GaneScene.unity b/Assets/Scenes/GaneScene.unity index ce6d3bf..86b2eb7 100644 --- a/Assets/Scenes/GaneScene.unity +++ b/Assets/Scenes/GaneScene.unity @@ -560,6 +560,10 @@ PrefabInstance: type: 3} insertIndex: -1 addedObject: {fileID: 1139635726} + - targetCorrespondingSourceObject: {fileID: 3294758251327466535, guid: 1c5dda3c7cd3cf742afcade5419faeab, + type: 3} + insertIndex: -1 + addedObject: {fileID: 1139635727} m_SourcePrefab: {fileID: 100100000, guid: 1c5dda3c7cd3cf742afcade5419faeab, type: 3} --- !u!1 &1139635724 stripped GameObject: @@ -593,6 +597,19 @@ Animator: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 +--- !u!114 &1139635727 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1139635724} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2604af0af2915a4449b6d902e37340ca, type: 3} + m_Name: + m_EditorClassIdentifier: + player: {fileID: 974939167} --- !u!1 &1228607671 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index aaa7eb3..17500fd 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -7,6 +7,8 @@ public class Player : MonoBehaviour [SerializeField] private float moveSpeed = 7f; + private bool isWalking; + private void Update() { Vector2 inputVector = new Vector2(0,0); @@ -33,9 +35,15 @@ public class Player : MonoBehaviour Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y); transform.position += moveDir * moveSpeed * Time.deltaTime; - float rotateSpeed = 10f; + isWalking = moveDir != Vector3.zero; + float rotateSpeed = 10f; transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed); } + public bool IsWalking() + { + return isWalking; + } + } diff --git a/Assets/Scripts/PlayerAnimator.cs b/Assets/Scripts/PlayerAnimator.cs new file mode 100644 index 0000000..88777d5 --- /dev/null +++ b/Assets/Scripts/PlayerAnimator.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerAnimator : MonoBehaviour +{ + + private const string IS_WALKING = "IsWalking"; + + [SerializeField] private Player player; + private Animator animator; + + private void Awake() + { + animator = GetComponent(); + } + + private void Update() + { + animator.SetBool(IS_WALKING, player.IsWalking()); + } + +} diff --git a/Assets/Scripts/PlayerAnimator.cs.meta b/Assets/Scripts/PlayerAnimator.cs.meta new file mode 100644 index 0000000..4e32a9f --- /dev/null +++ b/Assets/Scripts/PlayerAnimator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2604af0af2915a4449b6d902e37340ca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: