Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip fix ai air stuff #869

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion Assets/Prefabs/Input/PlayerAI.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ Transform:
m_CorrespondingSourceObject: {fileID: 5285924196574601758, guid: 2872a05bf8e94d541a70726bb35085f3, type: 3}
m_PrefabInstance: {fileID: 4812172812220652073}
m_PrefabAsset: {fileID: 0}
--- !u!4 &884546609350937026 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 5660690314102821867, guid: 2872a05bf8e94d541a70726bb35085f3, type: 3}
m_PrefabInstance: {fileID: 4812172812220652073}
m_PrefabAsset: {fileID: 0}
--- !u!4 &1198073272138160539 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 5938045475689792434, guid: 2872a05bf8e94d541a70726bb35085f3, type: 3}
Expand Down Expand Up @@ -249,7 +254,7 @@ MonoBehaviour:
bottomCaster: {fileID: 196519995927016420}
topCaster: {fileID: 3481771409427924515}
stepHeight: 0.5
playerRoot: {fileID: 0}
playerRoot: {fileID: 884546609350937026}
steppingIgnoreMask:
serializedVersion: 2
m_Bits: 0
Expand Down
11 changes: 11 additions & 0 deletions Assets/Scripts/Control&Input/AIMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ private void Update()
}
}

protected override bool IsInAir()
{
// TODO using stepping ground thing here doesn't really work...
return base.IsInAir();
}

public bool IsInAirRightNow()
{
return !IsGroundedAccurate();
}

protected override void FixedUpdate()
{
var direction = -transform.forward;
Expand Down
13 changes: 9 additions & 4 deletions Assets/Scripts/Control&Input/PlayerMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private IEnumerator LeapTimeout()
/// No, this does not work if the cast start at the bottom.
/// </summary>
/// <returns>Whether or not the player is in the air</returns>
private bool IsInAir()
protected virtual bool IsInAir()
{
bool isAir = !Physics.BoxCast(hitbox.bounds.center, new Vector3(.5f, .5f, .2f), Vector3.down, out RaycastHit hit, Quaternion.identity, 0.5f + airThreshold, groundCheckMask);
ground = isAir ? null : hit.collider;
Expand Down Expand Up @@ -444,7 +444,7 @@ private void UpdateRotation()
if (!CanLook)
return;
var lookSpeedFactor = inputManager.ZoomActive
? inputManager.IsMouseAndKeyboard ? LookSpeedZoom * mouseZoomSpeedFactor: LookSpeedZoom
? inputManager.IsMouseAndKeyboard ? LookSpeedZoom * mouseZoomSpeedFactor : LookSpeedZoom
: lookSpeed;
var lookInput = inputManager.IsMouseAndKeyboard
? inputManager.lookInput
Expand Down Expand Up @@ -475,12 +475,17 @@ private void OnDrawGizmos()
/// More accurate ground detection for use in stepping up edges. Uses raycast to check for ground directly beneath the player.
/// </summary>
/// <returns>true if player is touching the ground, false if not touching ground </returns>
private bool FindSteppingGround()
protected bool FindSteppingGround()
{
return IsGroundedAccurate() && state is GroundState.Grounded;
}

protected bool IsGroundedAccurate()
{
RaycastHit hitGround;
if (Physics.Raycast(playerRoot.position, Vector3.down, out hitGround, 0.01f))
{
if (hitGround.normal.y > 0.0001f && state == GroundState.Grounded)
if (hitGround.normal.y > 0.0001f)
{
return true;
}
Expand Down
9 changes: 7 additions & 2 deletions Assets/Scripts/Gamestate/AIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private IEnumerator LookForTargets()

var hasAmmoBoxBody = ammoBoxCollector.CanReload;
var isOutOfAmmo = gunController && gunController.stats.Ammo < 1;
var isInAir = aiMovement.enabled && aiMovement.StateIsAir;
var isInAir = aiMovement.IsInAirRightNow();
if (hasAmmoBoxBody && isOutOfAmmo && !isInAir)
{
var ammoBox = AmmoBox.GetClosestAmmoBoxForAI(transform.position);
Expand All @@ -248,7 +248,12 @@ private IEnumerator LookForTargets()
agent.stoppingDistance = itemStoppingDistance;
agent.SetDestination(DestinationTarget.position);
}
else if (!aiMovement || !aiMovement.enabled)
else if (!aiMovement.enabled && isInAir)
{
Debug.Log("DISABLING AGENT NOW");
DisableAgent();
}
else
{
FindPlayers();
}
Expand Down