From 3a3330dba6f622c3bfbc1a7fc9652b1ea4f50329 Mon Sep 17 00:00:00 2001 From: Tore Bergebakken Date: Wed, 23 Oct 2024 22:32:49 +0200 Subject: [PATCH 1/2] wip fix ai air stuff --- Assets/Scripts/Control&Input/AIMovement.cs | 5 +++++ Assets/Scripts/Control&Input/PlayerMovement.cs | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Control&Input/AIMovement.cs b/Assets/Scripts/Control&Input/AIMovement.cs index 18c18db84..ef90e91ef 100644 --- a/Assets/Scripts/Control&Input/AIMovement.cs +++ b/Assets/Scripts/Control&Input/AIMovement.cs @@ -30,6 +30,11 @@ private void Update() } } + protected override bool IsInAir() + { + return !FindSteppingGround(); + } + protected override void FixedUpdate() { var direction = -transform.forward; diff --git a/Assets/Scripts/Control&Input/PlayerMovement.cs b/Assets/Scripts/Control&Input/PlayerMovement.cs index fb28ac6a2..a8657cdfc 100644 --- a/Assets/Scripts/Control&Input/PlayerMovement.cs +++ b/Assets/Scripts/Control&Input/PlayerMovement.cs @@ -351,7 +351,7 @@ private IEnumerator LeapTimeout() /// No, this does not work if the cast start at the bottom. /// /// Whether or not the player is in the air - 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; @@ -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 @@ -475,7 +475,7 @@ private void OnDrawGizmos() /// More accurate ground detection for use in stepping up edges. Uses raycast to check for ground directly beneath the player. /// /// true if player is touching the ground, false if not touching ground - private bool FindSteppingGround() + protected bool FindSteppingGround() { RaycastHit hitGround; if (Physics.Raycast(playerRoot.position, Vector3.down, out hitGround, 0.01f)) From 6b106ac08a814f36fc2aabb07b19e02e1a37fca9 Mon Sep 17 00:00:00 2001 From: Tore Bergebakken Date: Sat, 26 Oct 2024 16:54:14 +0200 Subject: [PATCH 2/2] wip --- Assets/Prefabs/Input/PlayerAI.prefab | 7 ++++++- Assets/Scripts/Control&Input/AIMovement.cs | 8 +++++++- Assets/Scripts/Control&Input/PlayerMovement.cs | 7 ++++++- Assets/Scripts/Gamestate/AIManager.cs | 9 +++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Assets/Prefabs/Input/PlayerAI.prefab b/Assets/Prefabs/Input/PlayerAI.prefab index dbc3e09db..f24ee7cbc 100644 --- a/Assets/Prefabs/Input/PlayerAI.prefab +++ b/Assets/Prefabs/Input/PlayerAI.prefab @@ -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} @@ -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 diff --git a/Assets/Scripts/Control&Input/AIMovement.cs b/Assets/Scripts/Control&Input/AIMovement.cs index ef90e91ef..30f3b0ed6 100644 --- a/Assets/Scripts/Control&Input/AIMovement.cs +++ b/Assets/Scripts/Control&Input/AIMovement.cs @@ -32,7 +32,13 @@ private void Update() protected override bool IsInAir() { - return !FindSteppingGround(); + // TODO using stepping ground thing here doesn't really work... + return base.IsInAir(); + } + + public bool IsInAirRightNow() + { + return !IsGroundedAccurate(); } protected override void FixedUpdate() diff --git a/Assets/Scripts/Control&Input/PlayerMovement.cs b/Assets/Scripts/Control&Input/PlayerMovement.cs index a8657cdfc..768681fa4 100644 --- a/Assets/Scripts/Control&Input/PlayerMovement.cs +++ b/Assets/Scripts/Control&Input/PlayerMovement.cs @@ -476,11 +476,16 @@ private void OnDrawGizmos() /// /// true if player is touching the ground, false if not touching ground 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; } diff --git a/Assets/Scripts/Gamestate/AIManager.cs b/Assets/Scripts/Gamestate/AIManager.cs index 97963cc1d..b6dd8db96 100644 --- a/Assets/Scripts/Gamestate/AIManager.cs +++ b/Assets/Scripts/Gamestate/AIManager.cs @@ -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); @@ -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(); }