Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/SAIN/v17/.suo
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private bool CheckIfStuck()
TargetPosition = SAIN.CurrentTargetPosition;
if (TargetPosition != null)
{
GoToPoint(TargetPosition.Value, false);
//GoToPoint(TargetPosition.Value, false);
}
}
return true;
Expand Down
126 changes: 106 additions & 20 deletions Components/Bot Components/Classes/Core/SteeringClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,33 @@ public SteeringClass(BotOwner bot) : base(bot)
Logger = BepInEx.Logging.Logger.CreateLogSource(GetType().Name);
}

public bool ManualUpdate(bool useDefaultHear = true)
public void Update()
{
UpdateAimSway();
UpdateSmoothLook();
}

private void UpdateAimSway()
{
if (AimSwayTimer < Time.time)
{
AimSwayTimer = Time.time + 0.66f;
AimSway();
}
}

private void AimSway()
{
Vector3 random = Random.insideUnitSphere * 0.5f;
Quaternion randomRotation = Quaternion.Euler(random.x, random.y, random.z);
TargetSteerPoint = randomRotation * RealSteerTarget;
}

private float AimSwayTimer = 0f;

public bool SteerComplete => (TargetSteerPoint - RealSteerTarget).sqrMagnitude < 1f;

public bool Steer(bool useDefaultHear = true)
{
if (!SAIN.BotActive || SAIN.GameIsEnding)
{
Expand All @@ -22,7 +48,7 @@ public bool ManualUpdate(bool useDefaultHear = true)

if (SAIN.Enemy?.IsVisible == true)
{
LookToGoalEnemyPos();
LookToEnemy();
return true;
}
if (BotOwner.Memory.LastTimeHit > Time.time - 1f)
Expand All @@ -35,9 +61,10 @@ public bool ManualUpdate(bool useDefaultHear = true)
LookToUnderFirePos();
return true;
}
if (SAIN.LastHeardSound != null && SAIN.LastHeardSound.TimeSinceHeard < 2f && (SAIN.LastHeardSound.Position - BotOwner.Position).magnitude < 50f)
var sound = BotOwner.BotsGroup.YoungestPlace(BotOwner, 100f, false);
if (sound != null && Time.time - sound.CreatedTime < 2f)
{
LookToHearPos();
LookToHearPos(sound.Position);
return true;
}
else
Expand All @@ -46,17 +73,78 @@ public bool ManualUpdate(bool useDefaultHear = true)
{
BotOwner.LookData.SetLookPointByHearing();
}
else
{
LookToRandomPosition();
}
return false;
}
}

public void LookToGoalEnemyPos()
private Vector3 RealSteerTarget;

public Vector3 CurrentSteerPoint { get; private set; }

public Vector3 TargetSteerPoint { get; private set; }

public Vector3 CurrentSteerDirection => CurrentSteerPoint - BotPosition;

public Vector3 TargetSteerDirection => TargetSteerPoint - BotPosition;

private void UpdateSmoothLook()
{
float angle = Vector3.Angle(CurrentSteerDirection, TargetSteerDirection);
float divisor = angle > 10f ? 0.5f : 0.66f;
float lerp = Time.deltaTime / divisor;
Vector3 pos = Vector3.Lerp(CurrentSteerPoint, TargetSteerPoint, lerp);
CurrentSteerPoint = pos;
BotOwner.Steering.LookToPoint(pos, 999f);
}

public void LookToPoint(Vector3 point)
{
RealSteerTarget = point;
AimSway();
}

public void LookToDirection(Vector3 direction, bool flat)
{
if (flat)
{
direction.y = 0f;
}
Vector3 pos = SAIN.HeadPosition + direction;
LookToPoint(pos);
}

public void LookToRandomPosition()
{
if (RandomLookTimer < Time.time)
{
var Mask = LayerMaskClass.HighPolyWithTerrainMask;
var Start = SAIN.HeadPosition;
for (int i = 0; i < 10; i++)
{
var random = Random.onUnitSphere * 5f;
if (!Physics.Raycast(Start, random, 3f, Mask))
{
RandomLookTimer = Time.time + 2f * Random.Range(0.5f, 1.5f);
SAIN.Steering.LookToDirection(random, true);
break;
}
}
}
}

private float RandomLookTimer = 0f;

public void LookToEnemy()
{
var enemy = BotOwner.Memory.GoalEnemy;
var enemy = SAIN.Enemy;
if (enemy != null && enemy.CanShoot && enemy.IsVisible)
{
var pos = enemy.Person.MainParts[BodyPartType.body].Position;
BotOwner.Steering.LookToPoint(pos);
TargetSteerPoint = pos;
}
}

Expand All @@ -65,43 +153,41 @@ public void LookToPriorityEnemyPos()
var priority = SAIN.Enemy;
if (priority != null && priority.IsVisible && priority.EnemyChestPosition != null)
{
var enemyPos = priority.EnemyChestPosition;
BotOwner.Steering.LookToPoint(enemyPos);
var pos = priority.EnemyChestPosition;
LookToPoint(pos);
}
}

public void LookToUnderFirePos()
{
var underFirePos = SAIN.UnderFireFromPosition;
underFirePos.y += 1f;
BotOwner.Steering.LookToPoint(underFirePos);
var pos = SAIN.UnderFireFromPosition;
pos.y += 1f;
LookToPoint(pos);
}

public void LookToHearPos(bool visionCheck = false)
public void LookToHearPos(Vector3 soundPos, bool visionCheck = false)
{
var soundPos = SAIN.LastHeardSound.Position;

if (visionCheck)
{
soundPos.y += 0.1f;
var direction = soundPos - SAIN.HeadPosition;

if (!Physics.Raycast(SAIN.HeadPosition, direction, direction.magnitude, LayerMaskClass.HighPolyWithTerrainMask))
{
BotOwner.Steering.LookToPoint(soundPos);
LookToPoint(soundPos);
}
}
else
{
BotOwner.Steering.LookToPoint(soundPos);
LookToPoint(soundPos);
}
}

public void LookToLastHitPos()
{
var lastHitPos = BotOwner.Memory.LastHitPos;
lastHitPos.y += 1f;
BotOwner.Steering.LookToPoint(lastHitPos);
var pos = BotOwner.Memory.LastHitPos;
pos.y += 1f;
LookToPoint(pos);
}


Expand Down
69 changes: 46 additions & 23 deletions Components/Bot Components/Classes/Cover/CoverClass.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BepInEx.Logging;
using EFT;
using SAIN.Components;
using System.Linq;
using UnityEngine;

namespace SAIN.Classes
Expand Down Expand Up @@ -37,34 +38,56 @@ public CoverPoint ClosestPoint
{
get
{
var CoverA = CurrentCoverPoint;
var CoverB = CurrentFallBackPoint;
float? DistanceA = CoverA?.Distance;
float? DistanceB = CoverB?.Distance;

if (CoverA == null && CoverB == null)
if (CoverFinder.CoverPoints.Count > 0)
{
Logger.LogError("Both CoverPoints null");
return CoverFinder.CoverPoints[0];
}
return null;
}
}

if (DistanceA == null)
public CoverPoint FarPointEnemy
{
get
{
if (CoverFinder.CoverPoints.Count == 1)
{
if (DistanceB != null)
{
return CoverB;
}
return null;
return CoverFinder.CoverPoints.First();
}
if (DistanceB == null)
if (CoverFinder.CoverPoints.Count > 1)
{
if (DistanceA != null)
{
return CoverA;
}
return null;
var points = CoverFinder.CoverPoints.ToArray();
System.Array.Sort(points, CoverPointEnemyComparerer);
return points.Last();
}
return null;
}
}

return DistanceA.Value < DistanceB.Value ? CoverA : CoverB;
private int CoverPointEnemyComparerer(CoverPoint A, CoverPoint B)
{
if (A == null && B != null)
{
return 1;
}
else if (A != null && B == null)
{
return -1;
}
else if (A == null && B == null)
{
return 0;
}
else
{
if (SAIN.CurrentTargetPosition == null)
{
return 0;
}
Vector3 enemy = SAIN.CurrentTargetPosition.Value;
float ADist = (enemy - A.Position).sqrMagnitude;
float BDist = (enemy - B.Position).sqrMagnitude;
return ADist.CompareTo(BDist);
}
}

Expand All @@ -85,7 +108,7 @@ public bool DuckInCover()
}
if (ActiveCoverPoint.Collider.bounds.size.y < 1.5f)
{
SAIN.BotOwner.SetPose(0f);
SAIN.Mover.SetTargetPose(0f);
return true;
}
}
Expand Down Expand Up @@ -171,8 +194,8 @@ public CoverPoint ActiveCoverPoint
}
}
public CoverFinderComponent CoverFinder { get; private set; }
public CoverPoint CurrentCoverPoint => CoverFinder.CurrentCover;
public CoverPoint CurrentFallBackPoint => CoverFinder.CurrentFallBackPoint;
public CoverPoint CurrentCoverPoint => ClosestPoint;
public CoverPoint CurrentFallBackPoint => ClosestPoint;
protected ManualLogSource Logger;
}
}
Loading