From 229c4490c4d4ab3c8e0f81371a54b4486788dd73 Mon Sep 17 00:00:00 2001 From: Krazerleo Date: Tue, 17 May 2022 00:21:53 +0700 Subject: [PATCH] Finally bots can die. Player to. And another fixes. --- Assets/Prefabs/PlayerPrefab/Player.prefab | 114 ++++-------------- .../Greatest_map_ever/Greatest_map_ever.unity | 2 +- .../Leonid Animator/AnimatorHandler.cs | 16 +-- .../Player/CharacterLocomotion.cs | 25 +++- .../Leonid Animator/Player/InputHandler.cs | 5 +- Assets/Scripts/Bots/CharacterFactory.cs | 46 ++++--- Assets/Scripts/CameraScripts/CameraHandler.cs | 42 ++++--- Assets/Scripts/Character/Character.cs | 1 + Assets/Scripts/Character/NPC.cs | 18 +-- Assets/Scripts/Character/Player.cs | 11 +- Assets/Scripts/Managers/GameManager.cs | 9 +- Assets/Scripts/Managers/MapManager.cs | 11 +- Assets/Scripts/Misc/FlagZone.cs | 3 - Assets/Scripts/Weapons/Shooting.cs | 20 ++- Assets/Settings/Game Settings.asset | 8 +- 15 files changed, 160 insertions(+), 171 deletions(-) diff --git a/Assets/Prefabs/PlayerPrefab/Player.prefab b/Assets/Prefabs/PlayerPrefab/Player.prefab index 2e2ad85..e0e3a80 100644 --- a/Assets/Prefabs/PlayerPrefab/Player.prefab +++ b/Assets/Prefabs/PlayerPrefab/Player.prefab @@ -1394,10 +1394,9 @@ GameObject: - component: {fileID: 2528273238195332182} - component: {fileID: 2528273238195332176} - component: {fileID: 2528273238195332168} - - component: {fileID: 2851493361974364939} - component: {fileID: 5170482295850327424} - - component: {fileID: 5519976521156458274} - - component: {fileID: -4820536401884566159} + - component: {fileID: 8568640505362233545} + - component: {fileID: 5876264296742387244} m_Layer: 10 m_Name: Player m_TagString: Untagged @@ -1472,7 +1471,7 @@ Animator: m_Controller: {fileID: 9100000, guid: 3ebf60422b6cb1c498ee4cf238072b43, type: 2} m_CullingMode: 1 m_UpdateMode: 0 - m_ApplyRootMotion: 0 + m_ApplyRootMotion: 1 m_LinearVelocityBlending: 0 m_WarningMessage: m_HasTransformHierarchy: 1 @@ -1530,21 +1529,7 @@ MonoBehaviour: m_EditorClassIdentifier: anim: {fileID: 2528273238195332174} canRotate: 1 ---- !u!114 &2851493361974364939 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2528273238195332181} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: e5f5f761e43327448b64038300d71e5b, type: 3} - m_Name: - m_EditorClassIdentifier: - enemy: {fileID: 164324136889094180, guid: 2d8d8fcef9fc43144982428bd40ad6f0, type: 3} - isFiring: 0 - lookSpeed: 50 + isCrouching: 0 --- !u!114 &5170482295850327424 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1559,10 +1544,10 @@ MonoBehaviour: m_EditorClassIdentifier: raycast: {fileID: 9178730298827149128} firePoint: {fileID: 6083229256174510991} - _projectilePrefab: {fileID: 1990380580032880, guid: 46b312e00ed9c1f459ea9f0e55bfac77, + projectilePrefab: {fileID: 1990380580032880, guid: 46b312e00ed9c1f459ea9f0e55bfac77, type: 3} gun: {fileID: 6083229256174510991} ---- !u!114 &5519976521156458274 +--- !u!114 &8568640505362233545 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -1571,55 +1556,29 @@ MonoBehaviour: m_GameObject: {fileID: 2528273238195332181} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: e63e19e155f6b6348897150b67863072, type: 3} + m_Script: {fileID: 11500000, guid: 3d606407023147d7b4d530a9593e9697, type: 3} m_Name: m_EditorClassIdentifier: - moveSpeed: 1 - shiftAdditionalSpeed: 1 - mouseSensitivity: 0 - invertMouse: 0 - autoLockCursor: 0 - cam: {fileID: 5592602041335177245} - character: {fileID: 2528273238195332181} ---- !u!23 &-4820536401884566159 -MeshRenderer: + targetTransform: {fileID: 2528273238195566709} + cameraTransform: {fileID: 3401070369230030472} + lookSpeed: 0.1 + followSpeed: 0.1 + pivotSpeed: 0.03 + LookAngle: 0 + minimumPivot: -35 + maximumPivot: 35 +--- !u!114 &5876264296742387244 +MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2528273238195332181} m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a8c9a8e604d395c4ab9d03d28adc4982, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &2528273238195332183 GameObject: m_ObjectHideFlags: 0 @@ -3128,8 +3087,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5234455722044222527} m_LocalRotation: {x: -0.7071068, y: 0, z: 0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 1} - m_LocalScale: {x: 0.01, y: 0.01, z: 0.01} + m_LocalPosition: {x: 0, y: -0.642, z: 4.02} + m_LocalScale: {x: 0.03831688, y: 0.03831688, z: 0.03831688} m_Children: [] m_Father: {fileID: 3401070369230030472} m_RootOrder: 0 @@ -3141,7 +3100,7 @@ MeshFilter: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5234455722044222527} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} --- !u!23 &1446591995090098502 MeshRenderer: m_ObjectHideFlags: 0 @@ -3206,7 +3165,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5585342347362633954} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.099999994, y: 2.5029998, z: -1.8900003} + m_LocalPosition: {x: -0.049, y: 2.5029998, z: -1.8900003} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 7744902250868623004} @@ -3476,7 +3435,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 3808104189668072889} - - component: {fileID: 6900876834040779050} m_Layer: 0 m_Name: Camera Holder m_TagString: Untagged @@ -3499,26 +3457,6 @@ Transform: m_Father: {fileID: 2528273238195566709} m_RootOrder: 8 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &6900876834040779050 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7419068246808297193} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3d606407023147d7b4d530a9593e9697, type: 3} - m_Name: - m_EditorClassIdentifier: - targetTransform: {fileID: 2528273238195566709} - cameraTransform: {fileID: 3401070369230030472} - cameraPivotTransform: {fileID: 916820916668423615} - LookSpeed: 0.1 - FollowSpeed: 0.1 - PivotSpeed: 0.03 - minimumPivot: -35 - maximumPivot: 35 --- !u!1 &8287218850849767936 GameObject: m_ObjectHideFlags: 0 @@ -3545,7 +3483,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8287218850849767936} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.09401773, y: 0.40798557, z: 0.68032074} + m_LocalPosition: {x: 0.09401773, y: 2.297, z: -2.12} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 77805209700100364} diff --git a/Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity b/Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity index 6853fb1..c2cc87e 100644 --- a/Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity +++ b/Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity @@ -1774,7 +1774,7 @@ Mesh: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: pb_Mesh19226 + m_Name: pb_Mesh26546 serializedVersion: 10 m_SubMeshes: - serializedVersion: 2 diff --git a/Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs b/Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs index 6821141..5d662ec 100644 --- a/Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs +++ b/Assets/Scripts/Animators/Leonid Animator/AnimatorHandler.cs @@ -1,4 +1,6 @@ -using Unity.Mathematics; +using System; +using CameraScripts; +using Unity.Mathematics; using UnityEngine; namespace Animators.Leonid_Animator @@ -10,7 +12,7 @@ namespace Animators.Leonid_Animator private int _horizontal; private int _vertical; - private bool _isCrouching = false; + public bool isCrouching = false; private bool _isJumping; private int _crouch; @@ -77,14 +79,8 @@ namespace Animators.Leonid_Animator if (pressedCrouching == true) { - _isCrouching = !_isCrouching; - if (_isCrouching == true) - transform.Rotate(Vector3.up, 45); - else - { - transform.Rotate(Vector3.up, -45); - } - anim.SetBool(_crouch, _isCrouching); + isCrouching = !isCrouching; + anim.SetBool(_crouch, isCrouching); } anim.SetBool(_jump, pressedJumped); diff --git a/Assets/Scripts/Animators/Leonid Animator/Player/CharacterLocomotion.cs b/Assets/Scripts/Animators/Leonid Animator/Player/CharacterLocomotion.cs index ee26de2..b08d2f7 100644 --- a/Assets/Scripts/Animators/Leonid Animator/Player/CharacterLocomotion.cs +++ b/Assets/Scripts/Animators/Leonid Animator/Player/CharacterLocomotion.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; namespace Animators.Leonid_Animator.Player { @@ -19,15 +20,19 @@ namespace Animators.Leonid_Animator.Player [SerializeField] public float jumpForce; [Header("Stats")] - [SerializeField] private float movementSpeed = 5; + [SerializeField] private float movementSpeed = 25; [SerializeField] private float rotationSpeed = 10; - - private void Start() + + + private void Awake() { myRigidbody = GetComponent(); _inputHandler = GetComponent(); myAnimatorHandler = GetComponent(); - + } + + private void Start() + { _cameraObject = Camera.main.transform; myTransform = transform; myAnimatorHandler.Initialize(); @@ -70,6 +75,16 @@ namespace Animators.Leonid_Animator.Player _inputHandler.crouchPressed = false; } + public Vector3 GetMeshCenter() + { + if (myAnimatorHandler.isCrouching) + return transform.position + 1f * Vector3.up; + else + { + return transform.position + 2f * Vector3.up; + } + } + #region Movement private Vector3 _normalVector; diff --git a/Assets/Scripts/Animators/Leonid Animator/Player/InputHandler.cs b/Assets/Scripts/Animators/Leonid Animator/Player/InputHandler.cs index 0c3eaa4..6a2d50c 100644 --- a/Assets/Scripts/Animators/Leonid Animator/Player/InputHandler.cs +++ b/Assets/Scripts/Animators/Leonid Animator/Player/InputHandler.cs @@ -1,4 +1,5 @@ -using CameraScripts; +using System; +using CameraScripts; using UnityEngine; namespace Animators.Leonid_Animator.Player @@ -21,7 +22,7 @@ namespace Animators.Leonid_Animator.Player private CameraHandler _cameraHandler; - private void Awake() + private void Start() { _cameraHandler = CameraHandler.Singleton; if (_cameraHandler == null) diff --git a/Assets/Scripts/Bots/CharacterFactory.cs b/Assets/Scripts/Bots/CharacterFactory.cs index 1411c98..270b9fd 100644 --- a/Assets/Scripts/Bots/CharacterFactory.cs +++ b/Assets/Scripts/Bots/CharacterFactory.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Unity.Barracuda; using Unity.MLAgents.Policies; using UnityEngine; +using Random = UnityEngine.Random; public class CharacterFactory : MonoBehaviour { @@ -14,7 +16,7 @@ public class CharacterFactory : MonoBehaviour [SerializeField] private GameObject PlayerPrefab; private List bots = new List(); - public GameObject player { get; private set; } + public GameObject Player { get; private set; } private void Awake() { @@ -27,6 +29,11 @@ public class CharacterFactory : MonoBehaviour } } + private void Update() + { + print(Player == null); + } + private void Start() { var attcNum = SettingsReader.Instance.GetSettings.NumOfAttackers; @@ -36,20 +43,21 @@ public class CharacterFactory : MonoBehaviour if (humanAtc == 1 && humanDef == 1) throw new System.ArgumentException("Can be only one human player"); - - for (int i = 0; i < attcNum - humanAtc; i++) - InstantiateEntity(Team.Attackers, TypeAI.D0DiskAI, - spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)]); - for (int i = 0; i < defNum - humanDef; i++) - InstantiateEntity(Team.Defenders, TypeAI.D0DiskAI, - spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]); + if (humanAtc == 1) InstantiateEntity(Team.Attackers, TypeAI.HumanAI, spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)]); if (humanDef == 1) InstantiateEntity(Team.Defenders, TypeAI.HumanAI, spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]); - + + for (int i = 0; i < attcNum - humanAtc; i++) + InstantiateEntity(Team.Attackers, TypeAI.D0DiskAI, + spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)]); + for (int i = 0; i < defNum - humanDef; i++) + InstantiateEntity(Team.Defenders, TypeAI.D0DiskAI, + spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]); + GameManager.OnResetScene += ResetCharacters; } @@ -65,8 +73,9 @@ public class CharacterFactory : MonoBehaviour if (typeAi == TypeAI.HumanAI) { + print("added player to list"); gameobject.GetComponent().GetCharacter.Team = team; - player = gameobject; + Player = gameobject; } else { @@ -101,18 +110,23 @@ public class CharacterFactory : MonoBehaviour } } - public void ReSpawn(ICharacter character, ref Vector3 pos, ref int startPointId) + public void ReSpawn(ICharacter character, GameObject go) { character.ResetCharacter(); var team = character.GetCharacter.Team; + var ai = character.GetCharacter.TypeAi; NavPoint navPoint; if (team == Team.Attackers) navPoint = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)]; else navPoint = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)]; - pos = navPoint.Position; - startPointId = navPoint.PointId; + go.transform.position = navPoint.Position; + if (ai == TypeAI.D0DiskAI) + { + var mc =go.GetComponent(); + mc.PointStartID = navPoint.PointId; + } } private void ResetCharacters() @@ -131,9 +145,9 @@ public class CharacterFactory : MonoBehaviour { player.ResetCharacter(); if (player.GetCharacter.Team == Team.Attackers) - this.player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position; + this.Player.transform.position = spawnPointsForAttackersTeam[Random.Range(0, spawnPointsForAttackersTeam.Count)].Position; else - this.player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position; + this.Player.transform.position = spawnPointsForDefendersTeam[Random.Range(0, spawnPointsForDefendersTeam.Count)].Position; } } } \ No newline at end of file diff --git a/Assets/Scripts/CameraScripts/CameraHandler.cs b/Assets/Scripts/CameraScripts/CameraHandler.cs index f9ac420..522e5e6 100644 --- a/Assets/Scripts/CameraScripts/CameraHandler.cs +++ b/Assets/Scripts/CameraScripts/CameraHandler.cs @@ -1,4 +1,6 @@ using System; +using Animators.Leonid_Animator; +using Animators.Leonid_Animator.Player; using Unity.Mathematics; using UnityEngine; @@ -7,50 +9,52 @@ namespace CameraScripts public class CameraHandler : MonoBehaviour { public Transform targetTransform; - public Transform cameraTransform; - public Transform cameraPivotTransform; private Transform _myTransform; - private Vector3 _cameraTransformPosition; - private LayerMask ignoreLayers = ~(1 << 8 | 1 << 9 | 1 << 10); + [SerializeField] private Transform cameraTransform; public static CameraHandler Singleton; - [SerializeField] private float LookSpeed = 0.1f; - [SerializeField] private float FollowSpeed = 0.1f; - [SerializeField] private float PivotSpeed = 0.03f; - - private float _defaultPosition; - private float _lookAngle; + [SerializeField] private float lookSpeed = 0.1f; + [SerializeField] private float followSpeed = 0.1f; + [SerializeField] private float pivotSpeed = 0.03f; + + public float LookAngle; private float _pivotAngle; public float minimumPivot = -35; public float maximumPivot = 35; + private AnimatorHandler _animatorHandler; + private void Awake() { - Application.targetFrameRate = 60; Singleton = this; _myTransform = transform; - _defaultPosition = _myTransform.localPosition.z; + } + + private void Start() + { + _animatorHandler = gameObject.GetComponent(); + if (_animatorHandler == null) + print(gameObject.name); } public void TargetPosition(float delta) { - var toTargetPosition = Vector3.Lerp(_myTransform.position, targetTransform.position, delta /FollowSpeed); + var toTargetPosition = Vector3.Lerp(_myTransform.position, targetTransform.position, delta /followSpeed); _myTransform.position = toTargetPosition; } public void HandleCameraRotation(float delta, float mouseX, float mouseY) { - _lookAngle += (mouseX * LookSpeed) / delta; - _pivotAngle -= (mouseY * PivotSpeed) / delta; + LookAngle += (mouseX * lookSpeed) / delta; + _pivotAngle -= (mouseY * pivotSpeed) / delta; _pivotAngle = Mathf.Clamp(_pivotAngle, minimumPivot, maximumPivot); - + var rotation = Vector3.zero; - rotation.y = _lookAngle; - var targetRotation = Quaternion.Euler(rotation); - targetTransform.rotation = targetRotation; + rotation.y = LookAngle; + transform.rotation = Quaternion.Euler(rotation); } } } \ No newline at end of file diff --git a/Assets/Scripts/Character/Character.cs b/Assets/Scripts/Character/Character.cs index 3713998..34e4c36 100644 --- a/Assets/Scripts/Character/Character.cs +++ b/Assets/Scripts/Character/Character.cs @@ -4,6 +4,7 @@ public class Character public Team Team { get; set; } public float LastTimeHit = 0; public CharacterCondition Condition; + public TypeAI TypeAi; public Character() { diff --git a/Assets/Scripts/Character/NPC.cs b/Assets/Scripts/Character/NPC.cs index f0ede54..5b29fb3 100644 --- a/Assets/Scripts/Character/NPC.cs +++ b/Assets/Scripts/Character/NPC.cs @@ -204,18 +204,20 @@ public class NPC : Agent, ICharacter _condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - _condition.ArmourPoints * 0.5f))); _condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5)); OnDamageReceived?.Invoke(damage, GetCharacter.Team); - - if (_condition.HealthPoints < 0) + if (_condition.HealthPoints < 1) { - OnDeathEvent?.Invoke(true); - MapManager.AddDeathAttributeToPoints(_moveController.PointStartID, _moveController.PointEndID, - _moveController.DistanceToGo, _moveController.RemainingDistance); - var pos = gameObject.transform.position; - var id = _moveController.PointStartID; - CharacterFactory.Instance.ReSpawn(this, ref pos, ref id); + Die(); } } + private void Die() + { + OnDeathEvent?.Invoke(true); + MapManager.AddDeathAttributeToPoints(_moveController.PointStartID, _moveController.PointEndID, + _moveController.DistanceToGo, _moveController.RemainingDistance); + CharacterFactory.Instance.ReSpawn(this, gameObject); + } + public void ResetCharacter() { _condition.Reset(); diff --git a/Assets/Scripts/Character/Player.cs b/Assets/Scripts/Character/Player.cs index 5a9991a..6b892d2 100644 --- a/Assets/Scripts/Character/Player.cs +++ b/Assets/Scripts/Character/Player.cs @@ -27,8 +27,15 @@ public class Player : MonoBehaviour, ICharacter Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f))); Condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5)); - if (Condition.HealthPoints < 0) - OnDeathEvent?.Invoke(true); + if (Condition.HealthPoints < 1) + Die(); + } + + private void Die() + { + print("dead"); + OnDeathEvent?.Invoke(true); + CharacterFactory.Instance.ReSpawn(this, gameObject); } public void ResetCharacter() diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index 6f96bcb..3d5af73 100755 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Animators.Leonid_Animator.Player; using Unity.MLAgents; using UnityEngine; @@ -48,7 +49,7 @@ public class GameManager : MonoBehaviour if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) || (SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders)) { - if (distToNavPoint > (currentTransform - CharacterFactory.Instance.player.transform.position).magnitude) + if (distToNavPoint > (currentTransform - CharacterFactory.Instance.Player.transform.position).magnitude) return true; } return false; @@ -64,7 +65,7 @@ public class GameManager : MonoBehaviour if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) || (SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders)) { - if ((currentTransform - CharacterFactory.Instance.player.transform.position).magnitude < SettingsReader.Instance.GetSettings.ViewDistance) + if ((currentTransform - CharacterFactory.Instance.Player.transform.position).magnitude < SettingsReader.Instance.GetSettings.ViewDistance) return true; } return false; @@ -99,9 +100,9 @@ public class GameManager : MonoBehaviour if ((SettingsReader.Instance.GetSettings.HasHumanAttacker == true && oppositeTeam == Team.Attackers) || (SettingsReader.Instance.GetSettings.HasHumanDefender == true && oppositeTeam == Team.Defenders)) { - var player = CharacterFactory.Instance.player; + var player = CharacterFactory.Instance.Player; if (Physics.Raycast(position, - (player.GetComponent().bounds.center - position).normalized, + (player.GetComponent().GetMeshCenter() - position).normalized, out rayHit, SettingsReader.Instance.GetSettings.ViewDistance)) { diff --git a/Assets/Scripts/Managers/MapManager.cs b/Assets/Scripts/Managers/MapManager.cs index 24923b7..862824a 100755 --- a/Assets/Scripts/Managers/MapManager.cs +++ b/Assets/Scripts/Managers/MapManager.cs @@ -47,16 +47,15 @@ public class MapManager : MonoBehaviour var startNavPoint = _instance.IDToNavPoint[startPoint]; var endNavPoint = _instance.IDToNavPoint[endPoint]; float coef; - try + if (allDistance != 0) { coef = remainingDistance / allDistance; + startNavPoint.DeathAttr += 1 - coef; + endNavPoint.DeathAttr += coef; } - catch (System.ArithmeticException) + else { - Debug.LogError("Path Length is zero"); - return; + startNavPoint.DeathAttr += 1; } - startNavPoint.DeathAttr += 1 - coef; - endNavPoint.DeathAttr += coef; } } diff --git a/Assets/Scripts/Misc/FlagZone.cs b/Assets/Scripts/Misc/FlagZone.cs index 1b23950..8f1d697 100755 --- a/Assets/Scripts/Misc/FlagZone.cs +++ b/Assets/Scripts/Misc/FlagZone.cs @@ -30,9 +30,6 @@ public class FlagZone : MonoBehaviour case "Attacker": occupAttackers++; break; - default: - Debug.LogWarning("Entered non-team entity"); - break; } } private void OnTriggerExit(Collider other) diff --git a/Assets/Scripts/Weapons/Shooting.cs b/Assets/Scripts/Weapons/Shooting.cs index 9c47948..7adf8ce 100644 --- a/Assets/Scripts/Weapons/Shooting.cs +++ b/Assets/Scripts/Weapons/Shooting.cs @@ -11,7 +11,7 @@ public class Shooting : MonoBehaviour [SerializeField] private GameObject projectilePrefab; private float hSliderValue = 0.1f; - private float _fireCountdown = 1f; + private float _fireCountdown = 0.1f; public GameObject gun; private void Update() @@ -25,10 +25,24 @@ public class Shooting : MonoBehaviour { _fireCountdown = 0; _fireCountdown += hSliderValue; - Shoot(); + PlayerShoot(); } _fireCountdown -= Time.deltaTime; } + + private void PlayerShoot() + { + Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation); + if (Physics.Raycast(raycast.transform.position, + raycast.transform.forward, out var hit, + SettingsReader.Instance.GetSettings.ViewDistance)) + { + if (hit.transform.TryGetComponent(out var target)) + { + target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage); + } + } + } public void Shoot() { @@ -36,7 +50,7 @@ public class Shooting : MonoBehaviour raycast.transform.forward, out var hit, SettingsReader.Instance.GetSettings.ViewDistance)) { - if (hit.transform.TryGetComponent(out var target)) + if (hit.transform.TryGetComponent(out var target)) { Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation); target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage); diff --git a/Assets/Settings/Game Settings.asset b/Assets/Settings/Game Settings.asset index 14c2007..6e2ba35 100644 --- a/Assets/Settings/Game Settings.asset +++ b/Assets/Settings/Game Settings.asset @@ -19,9 +19,9 @@ MonoBehaviour: MovementSpeed: 1 DefTeamAI: 3 AtcTeamAI: 3 - NumOfDefenders: 2 - NumOfAttackers: 2 - HasHumanDefender: 0 + NumOfDefenders: 1 + NumOfAttackers: 1 + HasHumanDefender: 1 HasHumanAttacker: 0 HealthPickupAmount: 50 ArmourPickupAmount: 50 @@ -37,7 +37,7 @@ MonoBehaviour: DoDamageChanceInDirectPoint: 70 DoDamageChanceInRunning: 30 DoDamageChanceInCover: 25 - RifleDamage: 0 + RifleDamage: 100 RateOfFire: 1 CrouchingCoefficient: 1.4 atcMaterial: {fileID: 2100000, guid: ce639cf318364cf449d4fd87a69da579, type: 2}