Finally bots can die. Player to. And another fixes.
This commit is contained in:
@ -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);
|
||||
|
@ -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<Rigidbody>();
|
||||
_inputHandler = GetComponent<InputHandler>();
|
||||
myAnimatorHandler = GetComponent<AnimatorHandler>();
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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)
|
||||
|
@ -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<GameObject> bots = new List<GameObject>();
|
||||
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<Player>().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<MovementController>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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<AnimatorHandler>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ public class Character
|
||||
public Team Team { get; set; }
|
||||
public float LastTimeHit = 0;
|
||||
public CharacterCondition Condition;
|
||||
public TypeAI TypeAi;
|
||||
|
||||
public Character()
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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()
|
||||
|
@ -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<MeshRenderer>().bounds.center - position).normalized,
|
||||
(player.GetComponent<CharacterLocomotion>().GetMeshCenter() - position).normalized,
|
||||
out rayHit,
|
||||
SettingsReader.Instance.GetSettings.ViewDistance))
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<NPC>(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<NPC>(out var target))
|
||||
if (hit.transform.TryGetComponent<ICharacter>(out var target))
|
||||
{
|
||||
Instantiate(projectilePrefab, firePoint.transform.position, firePoint.transform.rotation);
|
||||
target.GetDamage(SettingsReader.Instance.GetSettings.RifleDamage);
|
||||
|
Reference in New Issue
Block a user