diff --git a/Game/.gitignore b/Game/.gitignore index 3c335ae..75a7fca 100644 --- a/Game/.gitignore +++ b/Game/.gitignore @@ -5,6 +5,7 @@ # Recommended: add any editor/OS/tool-specific ignore rules from the Global/ templates as needed. # See: https://github.com/github/gitignore/tree/main/Global # +.idea/ .utmp/ /[Ll]ibrary/ /[Tt]emp/ @@ -104,3 +105,4 @@ InitTestScene*.unity* # Auto-generated cache in Assets folder /[Aa]ssets/[Ss]ceneDependencyCache* +.idea/ diff --git a/Game/.vscode/extensions.json b/Game/.vscode/extensions.json deleted file mode 100644 index ddb6ff8..0000000 --- a/Game/.vscode/extensions.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "recommendations": [ - "visualstudiotoolsforunity.vstuc" - ] -} diff --git a/Game/.vscode/launch.json b/Game/.vscode/launch.json deleted file mode 100644 index da60e25..0000000 --- a/Game/.vscode/launch.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Attach to Unity", - "type": "vstuc", - "request": "attach" - } - ] -} \ No newline at end of file diff --git a/Game/.vscode/settings.json b/Game/.vscode/settings.json deleted file mode 100644 index 346e89e..0000000 --- a/Game/.vscode/settings.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "files.exclude": { - "**/.DS_Store": true, - "**/.git": true, - "**/.vs": true, - "**/.gitmodules": true, - "**/.vsconfig": true, - "**/*.booproj": true, - "**/*.pidb": true, - "**/*.suo": true, - "**/*.user": true, - "**/*.userprefs": true, - "**/*.unityproj": true, - "**/*.dll": true, - "**/*.exe": true, - "**/*.pdf": true, - "**/*.mid": true, - "**/*.midi": true, - "**/*.wav": true, - "**/*.gif": true, - "**/*.ico": true, - "**/*.jpg": true, - "**/*.jpeg": true, - "**/*.png": true, - "**/*.psd": true, - "**/*.tga": true, - "**/*.tif": true, - "**/*.tiff": true, - "**/*.3ds": true, - "**/*.3DS": true, - "**/*.fbx": true, - "**/*.FBX": true, - "**/*.lxo": true, - "**/*.LXO": true, - "**/*.ma": true, - "**/*.MA": true, - "**/*.obj": true, - "**/*.OBJ": true, - "**/*.asset": true, - "**/*.cubemap": true, - "**/*.flare": true, - "**/*.mat": true, - "**/*.meta": true, - "**/*.prefab": true, - "**/*.unity": true, - "build/": true, - "Build/": true, - "Library/": true, - "library/": true, - "obj/": true, - "Obj/": true, - "Logs/": true, - "logs/": true, - "ProjectSettings/": true, - "UserSettings/": true, - "temp/": true, - "Temp/": true - }, - "files.associations": { - "*.asset": "yaml", - "*.meta": "yaml", - "*.prefab": "yaml", - "*.unity": "yaml", - }, - "explorer.fileNesting.enabled": true, - "explorer.fileNesting.patterns": { - "*.sln": "*.csproj", - "*.slnx": "*.csproj" - }, - "dotnet.defaultSolution": "Game.slnx", - "dotnet.enableWorkspaceBasedDevelopment": false -} \ No newline at end of file diff --git a/Game/Assets/Images.meta b/Game/Assets/Images.meta new file mode 100644 index 0000000..b2888a3 --- /dev/null +++ b/Game/Assets/Images.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bc8547deda124e4418a491921dad1ff9 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Game/Assets/Prefabs/Branches.prefab b/Game/Assets/Prefabs/Branch.prefab similarity index 86% rename from Game/Assets/Prefabs/Branches.prefab rename to Game/Assets/Prefabs/Branch.prefab index 3617632..d960d87 100644 --- a/Game/Assets/Prefabs/Branches.prefab +++ b/Game/Assets/Prefabs/Branch.prefab @@ -11,8 +11,9 @@ GameObject: - component: {fileID: 2163867978973577705} - component: {fileID: 6893150318335556705} - component: {fileID: 5310886650056327379} + - component: {fileID: 5321372118810808216} m_Layer: 0 - m_Name: Branches + m_Name: Branch m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -126,7 +127,7 @@ BoxCollider2D: m_UsedByEffector: 1 m_CompositeOperation: 0 m_CompositeOrder: 0 - m_Offset: {x: 0, y: 0} + m_Offset: {x: -0.000000014901161, y: 0} m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} @@ -138,3 +139,22 @@ BoxCollider2D: m_AutoTiling: 0 m_Size: {x: 1, y: 1} m_EdgeRadius: 0 +--- !u!251 &5321372118810808216 +PlatformEffector2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8871780616060845038} + m_Enabled: 1 + m_UseColliderMask: 0 + m_ColliderMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RotationalOffset: 0 + m_UseOneWay: 1 + m_UseOneWayGrouping: 0 + m_SurfaceArc: 180 + m_UseSideFriction: 0 + m_UseSideBounce: 0 + m_SideArc: 1 diff --git a/Game/Assets/Prefabs/Branches.prefab.meta b/Game/Assets/Prefabs/Branch.prefab.meta similarity index 100% rename from Game/Assets/Prefabs/Branches.prefab.meta rename to Game/Assets/Prefabs/Branch.prefab.meta diff --git a/Game/Assets/Scenes/MainScene.unity b/Game/Assets/Scenes/MainScene.unity index bbf0573..efde622 100644 --- a/Game/Assets/Scenes/MainScene.unity +++ b/Game/Assets/Scenes/MainScene.unity @@ -119,6 +119,63 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1001 &274994935 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 2072448676} + m_Modifications: + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalPosition.x + value: 0.39 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalPosition.y + value: 1.94 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8871780616060845038, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_Name + value: Branch (1) + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} --- !u!1001 &279662124 PrefabInstance: m_ObjectHideFlags: 0 @@ -131,6 +188,10 @@ PrefabInstance: propertyPath: moveSpeed value: 10 objectReference: {fileID: 0} + - target: {fileID: -8535381027169538, guid: d56297e435f8410a584581d73d99d2e4, type: 3} + propertyPath: jumpingPower + value: 20 + objectReference: {fileID: 0} - target: {fileID: 2141180002423843430, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_Name value: PlayerDroplet @@ -139,21 +200,29 @@ PrefabInstance: propertyPath: m_Mass value: 1 objectReference: {fileID: 0} + - target: {fileID: 4266476263824402640, guid: d56297e435f8410a584581d73d99d2e4, type: 3} + propertyPath: m_Constraints + value: 4 + objectReference: {fileID: 0} - target: {fileID: 4266476263824402640, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_UseAutoMass value: 0 objectReference: {fileID: 0} - target: {fileID: 4266476263824402640, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_GravityScale - value: 25 + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 6566899495513628888, guid: d56297e435f8410a584581d73d99d2e4, type: 3} + propertyPath: m_LocalScale.y + value: 0.5957 objectReference: {fileID: 0} - target: {fileID: 6566899495513628888, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_LocalPosition.x - value: 0.05 + value: -4.63 objectReference: {fileID: 0} - target: {fileID: 6566899495513628888, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_LocalPosition.y - value: -0.02 + value: 3.74 objectReference: {fileID: 0} - target: {fileID: 6566899495513628888, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_LocalPosition.z @@ -190,8 +259,30 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 2141180002423843430, guid: d56297e435f8410a584581d73d99d2e4, type: 3} + insertIndex: -1 + addedObject: {fileID: 279662126} m_SourcePrefab: {fileID: 100100000, guid: d56297e435f8410a584581d73d99d2e4, type: 3} +--- !u!1 &279662125 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2141180002423843430, guid: d56297e435f8410a584581d73d99d2e4, type: 3} + m_PrefabInstance: {fileID: 279662124} + m_PrefabAsset: {fileID: 0} +--- !u!114 &279662126 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 279662125} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2b3b9fc97a2d39d2d84c4be43a79247a, type: 3} + m_Name: + m_EditorClassIdentifier: '::' + threshold: 0.05 + multiplier: 5 --- !u!1 &357828117 GameObject: m_ObjectHideFlags: 0 @@ -420,7 +511,17 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1001 &1065178480 +--- !u!4 &1124127124 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + m_PrefabInstance: {fileID: 274994935} + m_PrefabAsset: {fileID: 0} +--- !u!4 &1710653547 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + m_PrefabInstance: {fileID: 1958370634} + m_PrefabAsset: {fileID: 0} +--- !u!1001 &1890470405 PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 @@ -430,11 +531,11 @@ PrefabInstance: m_Modifications: - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} propertyPath: m_LocalPosition.x - value: -1.69 + value: -3.03753 objectReference: {fileID: 0} - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} propertyPath: m_LocalPosition.y - value: -1.24 + value: -0.38336 objectReference: {fileID: 0} - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} propertyPath: m_LocalPosition.z @@ -468,26 +569,6 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 5310886650056327379, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} - propertyPath: m_Size.x - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 5310886650056327379, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} - propertyPath: m_Size.y - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 5310886650056327379, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} - propertyPath: m_Offset.x - value: -0.000000014901161 - objectReference: {fileID: 0} - - target: {fileID: 5310886650056327379, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} - propertyPath: m_AutoTiling - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 5310886650056327379, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} - propertyPath: m_CompositeOperation - value: 0 - objectReference: {fileID: 0} - target: {fileID: 8871780616060845038, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} propertyPath: m_Name value: Branch @@ -495,40 +576,70 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 8871780616060845038, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} - insertIndex: -1 - addedObject: {fileID: 1065178483} + m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} ---- !u!4 &1065178481 stripped +--- !u!4 &1944302763 stripped Transform: m_CorrespondingSourceObject: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} - m_PrefabInstance: {fileID: 1065178480} + m_PrefabInstance: {fileID: 1890470405} m_PrefabAsset: {fileID: 0} ---- !u!1 &1065178482 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 8871780616060845038, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} - m_PrefabInstance: {fileID: 1065178480} - m_PrefabAsset: {fileID: 0} ---- !u!251 &1065178483 -PlatformEffector2D: +--- !u!1001 &1958370634 +PrefabInstance: m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1065178482} - m_Enabled: 1 - m_UseColliderMask: 0 - m_ColliderMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RotationalOffset: 0 - m_UseOneWay: 1 - m_UseOneWayGrouping: 0 - m_SurfaceArc: 180 - m_UseSideFriction: 0 - m_UseSideBounce: 0 - m_SideArc: 1 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 2072448676} + m_Modifications: + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalPosition.x + value: -6.2 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalPosition.y + value: 2.81 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8871780616060845038, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} + propertyPath: m_Name + value: Branch (2) + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3} --- !u!1 &2072448675 GameObject: m_ObjectHideFlags: 0 @@ -558,7 +669,9 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 1065178481} + - {fileID: 1944302763} + - {fileID: 1124127124} + - {fileID: 1710653547} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1660057539 &9223372036854775807 diff --git a/Game/Assets/Scenes/cems scene.unity b/Game/Assets/Scenes/cems scene.unity index f47f316..4f44f2c 100644 --- a/Game/Assets/Scenes/cems scene.unity +++ b/Game/Assets/Scenes/cems scene.unity @@ -137,7 +137,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4266476263824402640, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_GravityScale - value: 5 + value: 1 objectReference: {fileID: 0} - target: {fileID: 6566899495513628888, guid: d56297e435f8410a584581d73d99d2e4, type: 3} propertyPath: m_LocalPosition.x diff --git a/Game/Assets/Scripts/DamageHandler.cs b/Game/Assets/Scripts/DamageHandler.cs new file mode 100644 index 0000000..544c820 --- /dev/null +++ b/Game/Assets/Scripts/DamageHandler.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine; + +public class DamageHandler : MonoBehaviour +{ + public float threshold = 0.05f; + + public float multiplier = 5f; + + private void OnCollisionEnter(Collision collision) + { + throw new NotImplementedException(); + } +} diff --git a/Game/Assets/Scripts/DamageHandler.cs.meta b/Game/Assets/Scripts/DamageHandler.cs.meta new file mode 100644 index 0000000..05cc573 --- /dev/null +++ b/Game/Assets/Scripts/DamageHandler.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 2b3b9fc97a2d39d2d84c4be43a79247a \ No newline at end of file diff --git a/Game/Assets/Scripts/DropletMovement.cs b/Game/Assets/Scripts/DropletMovement.cs index 9c47c33..cd8b0b6 100644 --- a/Game/Assets/Scripts/DropletMovement.cs +++ b/Game/Assets/Scripts/DropletMovement.cs @@ -1,19 +1,27 @@ using UnityEngine; +using System.Collections; public class DropletMovement : MonoBehaviour { private Rigidbody2D rb; - public float moveSpeed = 5f; - public float jumpingPower = 5f; - private Vector2 movement; - private Animator playerAnim; //for animation - private float xInput; - //helper variables + // helper variables private bool isGrounded = true; - [SerializeField] private float dashSpeed; - [SerializeField] private float dashDuration; - private float dashTime; + private float facingDirection = 1f; + + // movement + private Vector2 movement; + public float jumpingPower = 5f; + public float moveSpeed = 5f; + + // dashing + private bool canDash = true; + private bool isDashing; + public float dashingPower = 24f; + public float dashingTime = 0.2f; + public float dashingCooldown = 1f; + + [SerializeField] private TrailRenderer tr; void Start() { @@ -22,18 +30,119 @@ public class DropletMovement : MonoBehaviour void Update() { + + //dashing + if (isDashing) + { + return; + } movement.x = Input.GetAxisRaw("Horizontal"); - - - - if (isGrounded && Input.GetKeyDown(KeyCode.Space)) + if (movement.x < 0) facingDirection = -1; + if (movement.x > 0) facingDirection = 1; + if (isGrounded && + (Input.GetKeyDown(KeyCode.Space) || + Input.GetKeyDown(KeyCode.UpArrow) || + Input.GetKeyDown(KeyCode.W))) { rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpingPower); } + if (Input.GetKeyDown(KeyCode.LeftShift) && canDash) + { + StartCoroutine(Dash()); + } + + //dropdown + if (!isGrounded){return;} + if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S)) + { + DropDown(); + } + } private void FixedUpdate() { + if (isDashing) + { + return; + } + rb.linearVelocity = new Vector2(movement.x * moveSpeed, rb.linearVelocity.y); } + + private IEnumerator Dash() + { + canDash = false; + isDashing = true; + + float originalGravity = rb.gravityScale; + rb.gravityScale = 0f; + + rb.linearVelocity = new Vector2(facingDirection * dashingPower, 0f); + + if (tr != null) + { + tr.emitting = true; + } + + yield return new WaitForSeconds(dashingTime); + + if (tr != null) + { + tr.emitting = false; + } + + rb.gravityScale = originalGravity; + isDashing = false; + + yield return new WaitForSeconds(dashingCooldown); + + canDash = true; + } + + private void OnCollisionEnter2D(Collision2D col) + { + isGrounded = true; + } + + private void OnCollisionExit2D(Collision2D col) + { + isGrounded = false; + } + + private void DropDown() + { + //when "s" or "down key" is pressed turn of/disable collider; + //move object slowly down (1 seconds, move down the height of the collision box) + //after that enable collider again + + if (isGrounded && (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))) + { + StartCoroutine(DropRoutine()); + } + } + + private IEnumerator DropRoutine() + { + Collider2D playerCollider = GetComponent(); + + playerCollider.isTrigger = true; + + float duration = 1f; + float elapsed = 0f; //measure time + + //move down the height of the collider + float dropDistance = playerCollider.bounds.size.y; + float speed = dropDistance/duration; + + while (elapsed < duration) + { + transform.Translate(Vector3.down * speed * Time.deltaTime); + elapsed += Time.deltaTime; //update time + yield return null; + } + + //enable collider --> not a trigger anymore + playerCollider.isTrigger = false; + } } \ No newline at end of file