Hi,
I’ve recently been plagued with this issue where my enemies sometimes will fall through. This is the first time I’ve seen it. I’m not able to reproduce it on my end unfortunately. In the video below instantiated enemies seem to sometimes fall through the scene. I ran it in the demo and all works fine for me, but this user it can be seen that the enemies slowly fall through the pathing system.
Is there any solution to fix this or you familiar with the reason it might happen sometimes?
Here is the video, and I’ve added a time stamp when it happens.
I’m using RichAI and some pretty simple movement scripts through the update loop.
I did add some code elsewhere that checks if a enemy drops below a certain depth on the terrain and ports them back up. In that same script I noticed that the constrain in graph sometimes ports them to 0,0,0 on the graph so I check for that and port them back to the spot I have saved using a coroutine. That seems to have fixed this rare occurrence, but I was wondering if you have noticed anything like this before. Here is my movement script below, sorry it’s a bit messy.
public void EnemyMovement()
{
if(currentTarget != null ){
if (currentTarget.dead == false) {
if (ranged == true && moving == false && beingAttackedBool == false && lineCastBlocked == false)
{
aiPath.endReachedDistance = 50.0f;
}
else
{
aiPath.endReachedDistance = 7.0f;
}
if (casting == false && moving == false && currentTarget.stealth == false && currentTarget.hide == false || seeStealth == true && casting == false)
{
if (beingAttackedBool == false)
{
aiPath.destination = currentTarget.transform.position;
destinationDistance = aiPath.remainingDistance;
}
else
{
destinationDistance = aiPath.remainingDistance;
}
}
else if (moving == false)
{
aiPath.destination = myTransform.position;
destinationDistance = 0;
//cause idle stance to fire off as if we were casting it would clear our target.
//currentTarget = null;
}
else
{
//added to prevent casting and moving if the above doesn't happen.
aiPath.destination = myTransform.position;
destinationDistance = 0;
}
if ((destinationDistance - aiPath.endReachedDistance) <= 0.0f) {
if (anim != null) {
//Debug.Log ("Battle1");
anim.SetBool ("Battle", true);
anim.SetBool ("Run", false);
anim.SetBool ("Idle", false);
//took away lookat so our enemies would stop slanting
if (currentTarget != null && casting == false)
{
var point = currentTarget.transform.position;
point.y = transform.position.y;
if (enemyAbilitiesScript.stopLookat == false)
{
transform.LookAt(point);
}
}
}
} else if ((destinationDistance - aiPath.endReachedDistance) > 0.0f) {
if (anim != null) {
//Debug.Log ("Run1");
anim.SetBool ("Battle", false);
anim.SetBool ("Run", true);
anim.SetBool ("Idle", false);
}
} else {
//transform.LookAt (currentTarget.transform.position);
}
}
}
else if(moving == true) {
if ((destinationDistance - aiPath.endReachedDistance) < 0.0f) {
if (anim != null) {
//Debug.Log ("Battle");
anim.SetBool ("Battle", true);
anim.SetBool ("Run", false);
anim.SetBool ("Idle", false);
//transform.LookAt (currentTarget.transform.position);
}
} else if ((destinationDistance - aiPath.endReachedDistance) >= 0.0f) {
if (anim != null) {
//Debug.Log ("Run");
anim.SetBool ("Battle", false);
anim.SetBool ("Run", true);
anim.SetBool ("Idle", false);
}
}
}
}