diff --git a/.vscode/settings.json b/.vscode/settings.json index 7e288fc..a9f994b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -51,5 +51,7 @@ "temp/": true, "Temp/": true }, - "editor.rulers": [80] + "editor.rulers": [80], + "editor.tabSize": 2, + "prettier.tabWidth": 2 } diff --git a/Assets/Prefabs/Enemy.prefab b/Assets/Prefabs/Enemy.prefab index 2b0144a..3dc4b7b 100644 --- a/Assets/Prefabs/Enemy.prefab +++ b/Assets/Prefabs/Enemy.prefab @@ -92,8 +92,8 @@ NavMeshAgent: m_Enabled: 1 m_AgentTypeID: 0 m_Radius: 0.5 - m_Speed: 2.59 - m_Acceleration: 8 + m_Speed: 1.55 + m_Acceleration: 2.82 avoidancePriority: 50 m_AngularSpeed: 120 m_StoppingDistance: 0 diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index 781491c..9bf638e 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44057134, g: 0.48920023, b: 0.569343, a: 1} + m_IndirectSpecularColor: {r: 0.44057152, g: 0.4892007, b: 0.5693435, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -2488,7 +2488,7 @@ Mesh: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: pb_Mesh36606 + m_Name: pb_Mesh28168 serializedVersion: 10 m_SubMeshes: - serializedVersion: 2 @@ -2713,7 +2713,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 6c7eefc8f6b5e68458f28981e3eb5196, type: 3} m_Name: m_EditorClassIdentifier: - enemyPrefab: {fileID: 0} + enemyPrefab: {fileID: 2422363816341469345, guid: 878f06b5ada303f47b84bdd84f0d4917, type: 3} --- !u!1001 &1876611742 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GameManagerScript.cs b/Assets/Scripts/GameManagerScript.cs index 8284d6f..9f263a8 100644 --- a/Assets/Scripts/GameManagerScript.cs +++ b/Assets/Scripts/GameManagerScript.cs @@ -23,7 +23,7 @@ System.Collections.IEnumerator SpawnLoop(GameObject prefab) { while (true) { - for (int i = 0; i < 5; i++) + for (int i = 0; i < 1; i++) { var vector2 = Random.insideUnitCircle * 5; diff --git a/Assets/Scripts/PlayerScript.cs b/Assets/Scripts/PlayerScript.cs index 2f4a8be..bd3b225 100644 --- a/Assets/Scripts/PlayerScript.cs +++ b/Assets/Scripts/PlayerScript.cs @@ -10,27 +10,37 @@ public class PlayerScript : MonoBehaviour Vector2 currentMoveInput; Vector2 processedMoveInput; Vector2 lastMove; - + Vector3 characterVelocity; Animator? anima; + GameObject? model; float lastMoveTimestamp; int killCount; bool attackLock; - System.Collections.IEnumerator SpawnLoop() + System.Collections.IEnumerator AttackRoutine() { anima?.SetBool("attack", true); attackLock = true; + yield return new WaitForSeconds(0.4f); + HandleAttack(); - attackLock = false; + anima?.SetBool("attack", false); + attackLock = false; } void HandleAttack() { - Debug.DrawRay(transform.position, transform.position + new Vector3{x = currentMoveInput.x, z = currentMoveInput.y}, Color.red); - var colliders = Physics.OverlapSphere(transform.position + new Vector3{x = currentMoveInput.x, z = currentMoveInput.y}, 1.7f, 0b1000000); + var offset = characterVelocity.normalized; + + var colliders = Physics.OverlapSphere( + transform.position + offset, + 1f, + 0b1000000 + ); + foreach (var collider in colliders) { var enemyDied = collider.transform.parent.gameObject @@ -60,15 +70,32 @@ void HandleMovement(CharacterController controller) controller.SimpleMove(Vector3.ClampMagnitude(move, 1f) * 4f); } + void HandleModelAnimation(GameObject model) + { + model.transform.rotation = + Quaternion.Lerp( + model.transform.rotation, + Quaternion.Euler( + 0f, + Mathf.Atan2(characterVelocity.x, characterVelocity.z) * Mathf.Rad2Deg, + 0f + ), + .1f + ); + } + public void Fire(InputAction.CallbackContext context) { - if(attackLock) { + if (attackLock) + { return; } + if (context.performed) { var value = context.ReadValue(); - StartCoroutine(SpawnLoop()); + + StartCoroutine(AttackRoutine()); } } @@ -104,14 +131,23 @@ public void MoveCheck() { currentMoveInput = Vector2.zero; } - anima?.SetFloat("speed", (controller?.velocity.magnitude??0f)/1.2f); + + var tempCharacterVelocity = controller?.velocity ?? Vector3.zero; + + if (tempCharacterVelocity.magnitude > .1f) + { + characterVelocity = tempCharacterVelocity; + } + + anima?.SetFloat("speed", (controller?.velocity.magnitude ?? 0f) / 1.2f); } void Awake() { controller = GetComponent(); playerInput = GetComponent(); - anima = transform.Find("DogPolyart").GetComponent(); + model = transform.Find("DogPolyart").gameObject; + anima = model.GetComponent(); } void OnGUI() @@ -127,5 +163,10 @@ void Update() { HandleMovement(controller: controller); } + + if (model != null) + { + HandleModelAnimation(model); + } } }