movement fix. ai movement

This commit is contained in:
dddushesss 2022-01-10 17:11:07 +03:00
parent 722b8da02b
commit ff5bdd180a
13 changed files with 129 additions and 88 deletions

View File

@ -58,7 +58,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0.036904335, b: 1, a: 1}
m_Color: {r: 1, g: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1

View File

@ -18,7 +18,7 @@ GameObject:
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &2395323453841137154
Transform:
@ -49,7 +49,10 @@ MonoBehaviour:
coordinates:
x: 0
z: 0
color: {r: 0, g: 0, b: 0, a: 0}
gCost: 0
hCost: 0
fCost: 0
parent: {fileID: 0}
neighbors:
- {fileID: 0}
- {fileID: 0}

View File

@ -24,5 +24,5 @@ MonoBehaviour:
- {fileID: 8300000, guid: d657487da1404a34f835a7631432b835, type: 3}
- {fileID: 8300000, guid: 5481b8f08252dd7499af6b48ad6c5354, type: 3}
- {fileID: 8300000, guid: 2b1056532f20f3248910d138da8358b9, type: 3}
hardCapture: {fileID: 8300000, guid: 72cf5153f4959df4eb30db3dc01d4e24, type: 3}
hardCapture: {fileID: 8300000, guid: d657487da1404a34f835a7631432b835, type: 3}
death: {fileID: 8300000, guid: 158e2b6cd6cdcba49bc9f9c1cb29d84b, type: 3}

View File

@ -14,12 +14,12 @@ MonoBehaviour:
m_EditorClassIdentifier:
_weapons:
- name: StandartAttac
icon: {fileID: 3777131139682951229, guid: dcb79c5472cbd5f4eb050a4acc4b197e, type: 3}
icon: {fileID: 3777131139682951229, guid: e85f2abe991b09140ac9b67cf8cb24a1, type: 3}
objectToThrow: {fileID: 4746165193704193263, guid: 4e7523811a052fd46acf941fc69c8c98,
type: 3}
VFXGameObject: {fileID: 2957420090356197408, guid: 5d1244f7b80cadd428a70173a01ce889,
type: 3}
manaCost: 10
modifiedDamage: 0
damage: 10
speed: 1
disnatce: 5
@ -28,12 +28,12 @@ MonoBehaviour:
shotSound: {fileID: 8300000, guid: 9ea918c6c23577f4e885a8490d2f2046, type: 3}
hitSound: {fileID: 8300000, guid: 6c42231c18643dc4d9d8f8d15bc4735b, type: 3}
- name: Laser
icon: {fileID: 3777131139682951229, guid: e85f2abe991b09140ac9b67cf8cb24a1, type: 3}
icon: {fileID: 3777131139682951229, guid: dcb79c5472cbd5f4eb050a4acc4b197e, type: 3}
objectToThrow: {fileID: 7219588875883387333, guid: ab214974cd498df42867306700ba5fd2,
type: 3}
VFXGameObject: {fileID: 8715260329460421181, guid: e0388f43a34de79458c79763de903ffb,
type: 3}
manaCost: 15
modifiedDamage: 0
damage: 30
speed: 0.5
disnatce: 3

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using AI;
using Controller;
using Data;
@ -14,34 +15,45 @@ namespace DefaultNamespace.AI
{
private Unit _enemy;
private Camera _camera;
private AIManager _manager;
public Queue<HexDirection> currentPath;
public Action<AIAgent> OnAgentInited;
public Unit Enemy => _enemy;
public AIAgent(UnitInfo enemyInfo, Unit enemy)
public AIAgent(UnitInfo enemyInfo, Unit enemy, AIManager manager)
{
currentPath = new Queue<HexDirection>();
_enemy = enemy;
_camera = Camera.main;
_enemy.OnDeath += AgentDeath;
enemy.onPlayerSpawned += InitAgent;
_manager = manager;
}
private void AgentDeath(Unit unit)
{
AIManager.Instance.RemoveAgent(this);
}
public void InitAgent(GameObject unit)
private void InitAgent(GameObject unit)
{
_manager.AddAgent(this);
HexManager.agents.Add(unit, this);
OnAgentInited?.Invoke(this);
}
public void Move(Vector2 direction)
{
_enemy.Move(DirectionHelper.VectorToDirection(direction));
}
public void FixedExecute()
{
//throw new System.NotImplementedException();
if (currentPath.Count > 0 && !_enemy.IsBusy)
{
_enemy.Move(currentPath.Dequeue());
}
else if(currentPath.Count == 0)
{
_manager.SetBehaviour(BotState.Patrol, this);
}
}
public void Execute()

View File

@ -15,9 +15,11 @@ namespace AI
private List<AIAgent> _agents;
private int _triesToCalculatePath = 0;
private int _maxTriesToCalculatePath = 5;
private Dictionary<AIAgent, Queue<HexCell>> _pathToPatrol;
private static AIManager _instance;
public static AIManager Instance
{
get => _instance;
@ -27,10 +29,9 @@ namespace AI
public AIManager(List<AIAgent> agents)
{
_agents = agents;
_pathToPatrol = new Dictionary<AIAgent, Queue<HexCell>>();
agents.ForEach(agent =>
{
_pathToPatrol.Add(agent, new Queue<HexCell>());
SetBehaviour(BotState.Patrol, agent);
});
}
@ -38,7 +39,7 @@ namespace AI
public AIManager()
{
_agents = new List<AIAgent>();
_pathToPatrol = new Dictionary<AIAgent, Queue<HexCell>>();
Instance = this;
HexManager.agents = new Dictionary<GameObject, AIAgent>();
}
@ -59,29 +60,29 @@ namespace AI
private void InitAI(AIAgent agent)
{
_pathToPatrol.Add(agent, new Queue<HexCell>());
SetBehaviour(BotState.Patrol, agent);
}
private void StartPatrolBehaviour(AIAgent agent)
{
HexManager.GetNearestDifferCell(agent.Enemy.Color, _pathToPatrol[agent]);
while (_pathToPatrol[agent] == null && _triesToCalculatePath < _maxTriesToCalculatePath)
HexManager.GetNearestDifferCell(agent.Enemy.Color, agent.currentPath);
while (agent.currentPath.Count == 0 && _triesToCalculatePath < _maxTriesToCalculatePath)
{
HexManager.GetNearestDifferCell(agent.Enemy.Color, _pathToPatrol[agent]);
HexManager.GetNearestDifferCell(agent.Enemy.Color, agent.currentPath);
_triesToCalculatePath++;
}
MoveAlongPath(agent);
_triesToCalculatePath = 0;
}
private void SetBehaviour(BotState state, AIAgent agent)
public void SetBehaviour(BotState state, AIAgent agent)
{
switch (state)
{
case BotState.Patrol:
MoveAlongPath(agent);
StartPatrolBehaviour(agent);
break;
case BotState.Agressive:
// MoveToEnemy(_currentEnemy);
@ -104,30 +105,26 @@ namespace AI
}
}
private void MoveAlongPath(AIAgent agent)
{
//Debug.Log("try to move next point");
if (_pathToPatrol != null && _pathToPatrol[agent].Count > 0) //recalculate existing path or start anew one
{
var start = HexManager.UnitCurrentCell[agent.Enemy.Color].cell.transform.position;
var end = _pathToPatrol[agent].Dequeue().transform.position;
var dir = DirectionHelper.DirectionTo(start, end);
agent.Move(new Vector2(dir.x, dir.z));
}
else
{
StartPatrolBehaviour(agent);
}
}
// private void MoveAlongPath(AIAgent agent)
// {
// //Debug.Log("try to move next point");
// if (_pathToPatrol != null && _pathToPatrol[agent].Count > 0) //recalculate existing path or start anew one
// {
// var start = HexManager.UnitCurrentCell[agent.Enemy.Color].cell.transform.position;
// var end = _pathToPatrol[agent].Dequeue().transform.position;
// var dir = DirectionHelper.DirectionTo(start, end);
// agent.Move(new Vector2(dir.x, dir.z));
// }
// else
// {
// StartPatrolBehaviour(agent);
// }
// }
public void FixedExecute()
{
for (int i = 0; i < _pathToPatrol.Count; i++)
{
if (!_agents[i].Enemy.IsBusy)
SetBehaviour(BotState.Patrol, _agents[i]);
}
}
}

View File

@ -66,9 +66,8 @@ namespace Controller
var enemyController = new EnemyController(unit, enemy);
controllers.Add(enemyController);
units.Add(enemy);
AIAgent agent = new AIAgent(unit, enemy);
aiManager.AddAgent(agent);
enemy.onPlayerSpawned += agent.InitAgent;
AIAgent agent = new AIAgent(unit, enemy, aiManager);
controllers.Add(agent);
}
});

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AI;
using DefaultNamespace;
using DefaultNamespace.AI;
@ -15,16 +16,27 @@ namespace HexFiled
public static Dictionary<UnitColor, List<HexCell>> CellByColor;
public static Dictionary<GameObject, AIAgent> agents;
public static void GetNearestDifferCell(UnitColor color, Queue<HexCell> path)
public static void GetNearestDifferCell(UnitColor color, Queue<HexDirection> path)
{
HexCell end = UnitCurrentCell[color].cell;
var itters = 0;
var neighbours = end.GetListNeighbours().Where(cell => cell != null && cell.Color != color).ToList();
if (neighbours.Any())
{
var dir = DirectionHelper.DirectionTo(end.transform.position,
neighbours[Random.Range(0, neighbours.Count)].transform.position);
path.Enqueue(DirectionHelper.VectorToDirection(new Vector2(dir.x, dir.z)));
return;
}
while (end.Color == color)
{
var tmp = end;
var dir = HexDirection.E;
do
{
end = tmp.Neighbors[Random.Range(0, 6)];
dir = (HexDirection)Random.Range(0, 6);
end = tmp.GetNeighbor(dir);
itters++;
} while (end == null && itters < 5);
@ -32,7 +44,7 @@ namespace HexFiled
{
return;
}
path.Enqueue(end);
path.Enqueue(dir);
}
}

View File

@ -171,15 +171,9 @@ namespace HexFiled
List<HexCell> openList = new List<HexCell>();
foreach (var neighbour in currentCell.GetListNeighbours())
foreach (var neighbour in currentCell.GetListNeighbours()
.Where(neighbour => neighbour != null && !closedList.Contains(neighbour) && neighbour.Color == start.Color))
{
if (neighbour == null)
{
return (true, null);
}
if (closedList.Contains(neighbour) || neighbour.Color != start.Color) continue;
openList.Add(neighbour);
if (neighbour.GetListNeighbours().Contains(end))
{

View File

@ -111,7 +111,6 @@ namespace Units
{
_isBusy = true;
_isCapturing = _data.color != _cell.GetNeighbor(direction).Color;
var previousCell = _cell;
_cell = _cell.GetNeighbor(direction);
HexManager.UnitCurrentCell[_data.color] = ( _cell, this );
RotateUnit(new Vector2((_cell.transform.position - _instance.transform.position).normalized.x,
@ -123,6 +122,10 @@ namespace Units
private void CaptureHex()
{
if (_data.isPlayer)
{
Debug.Log("Player");
}
_cell.PaintHex(_data.color);
}
@ -156,11 +159,7 @@ namespace Units
{
var neigh = _cell.GetNeighbor((HexDirection)i);
neigh?.PaintHex(_data.color);
for (int j = 0; j < 6; j++)
{
neigh?.GetNeighbor((HexDirection)j)?.PaintHex(_data.color);
}
}
//
@ -213,9 +212,9 @@ namespace Units
{
_isBusy = false;
_animator.SetBool("isMoving", _isBusy);
if (!_isCapturing)
{
_isHardToCapture = false;
return;
}

View File

@ -59,7 +59,7 @@ public class UnitView : MonoBehaviour
_unit.BarCanvas.CaptureBar.gameObject.SetActive(true);
_sequence = DOTween.Sequence();
_sequence.Append(_unit.BarCanvas.CaptureBar.DOFillAmount(1f, 0f).SetEase(Ease.Linear).OnComplete(() =>
_sequence.Append(_unit.BarCanvas.CaptureBar.DOFillAmount(1f, 1f).SetEase(Ease.Linear).OnComplete(() =>
{
_capureHex?.Invoke();
_unit.BarCanvas.CaptureBar.DOFillAmount(0f, 1f).SetEase(Ease.Linear).OnComplete(()=>_unit.IsBusy = false);
@ -67,6 +67,7 @@ public class UnitView : MonoBehaviour
MusicController.Instance.PlayRandomClip(MusicController.Instance.MusicData.SfxMusic.Captures,
cell.gameObject);
}));
_sequence.Play();
}

View File

@ -28,6 +28,7 @@ GraphicsSettings:
m_LensFlare:
m_Mode: 1
m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
m_VideoShadersIncludeMode: 2
m_AlwaysIncludedShaders:
- {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0}
@ -47,7 +48,24 @@ GraphicsSettings:
m_TransparencySortAxis: {x: 0, y: 0, z: 1}
m_DefaultRenderingPath: 1
m_DefaultMobileRenderingPath: 1
m_TierSettings: []
m_TierSettings:
- serializedVersion: 5
m_BuildTarget: 7
m_Tier: 0
m_Settings:
standardShaderQuality: 0
renderingPath: 1
hdrMode: 2
realtimeGICPUUsage: 25
useReflectionProbeBoxProjection: 0
useReflectionProbeBlending: 0
useHDR: 0
useDetailNormalMap: 0
useCascadedShadowMaps: 0
prefer32BitShadowMaps: 0
enableLPPV: 0
useDitherMaskForAlphaBlendedShadows: 0
m_Automatic: 1
m_LightmapStripping: 0
m_FogStripping: 0
m_InstancingStripping: 0
@ -63,5 +81,5 @@ GraphicsSettings:
m_AlbedoSwatchInfos: []
m_LightsUseLinearIntensity: 0
m_LightsUseColorTemperature: 0
m_DefaultRenderingLayerMask: 1
m_LogWhenShaderIsCompiled: 0
m_AllowEnlightenSupportForUpgradedProject: 0

View File

@ -18,7 +18,7 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 1
skinWeights: 1
textureQuality: 1
anisotropicTextures: 0
antiAliasing: 0
@ -40,11 +40,12 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Low
pixelLightCount: 0
shadows: 0
shadows: 1
shadowResolution: 0
shadowProjection: 1
shadowCascades: 1
@ -53,11 +54,11 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 0
antiAliasing: 0
softParticles: 0
antiAliasing: 2
softParticles: 1
softVegetation: 0
realtimeReflectionProbes: 0
billboardsFaceCameraPosition: 0
@ -75,6 +76,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Medium
@ -88,10 +90,10 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 0
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
antiAliasing: 4
softParticles: 0
softVegetation: 0
realtimeReflectionProbes: 0
@ -99,7 +101,7 @@ QualitySettings:
vSyncCount: 1
lodBias: 0.7
maximumLODLevel: 0
streamingMipmapsActive: 0
streamingMipmapsActive: 1
streamingMipmapsAddAllCameras: 1
streamingMipmapsMemoryBudget: 512
streamingMipmapsRenderersPerFrame: 512
@ -110,12 +112,13 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: High
pixelLightCount: 2
shadows: 2
shadowResolution: 1
shadowResolution: 2
shadowProjection: 1
shadowCascades: 2
shadowDistance: 40
@ -123,10 +126,10 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 2
skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 0
antiAliasing: 4
softParticles: 0
softVegetation: 1
realtimeReflectionProbes: 1
@ -145,6 +148,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Very High
@ -158,10 +162,10 @@ QualitySettings:
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowmaskMode: 1
blendWeights: 4
skinWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
antiAliasing: 4
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
@ -180,6 +184,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
- serializedVersion: 2
name: Ultra
@ -191,12 +196,12 @@ QualitySettings:
shadowDistance: 150
shadowNearPlaneOffset: 3
shadowCascade2Split: 0.33333334
shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
shadowCascade4Split: {x: 0.06666667, y: 0.19999999, z: 0.47391957}
shadowmaskMode: 1
blendWeights: 4
skinWeights: 4
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
antiAliasing: 8
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
@ -215,6 +220,7 @@ QualitySettings:
asyncUploadBufferSize: 16
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
customRenderPipeline: {fileID: 0}
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 2