Character Controller + Lag = Teleporting
Hey guys.
I'm working on a fairly robust game with another developer and we've been having a really serious issue with (I believe) the character controller. Specifically, if there's ever a large lag spike (as there are somewhat frequently - the code's not well optimized in some parts) there's a chance that the character controller will wing right through all nearby colliders and fall out of bounds.
It happens pseudo randomly, but I've noticed that it seems to be somewhat predictable, such as standing next to certain objects (nothing weird about them - just tables with colliders).
The lag often is a cause of large chunks of a level having SetActive(true) called on them in one frame or multiple objects being instantiated in one frame. These objects sometimes have colliders/rigidbodies attached but don't seem to be in any direct contact to the character controller.
I can very consistently make it happen by moving towards certain walls (again, very normal walls) and alt-tabbing while my character is still moving also seems to cause the issue predictably, which is VERY strange.
Has anyone ever experienced anything like this with the character controller? I'd give a code sample but honestly not even sure where from the codebase would be pertinent other than
if (Time.deltaTime < 0.15f)
{
if (applyGravity && noClip == false)
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
Which seems awfully straightforward to me. Obviously moveDirection gets changed elsewhere in the function too but it's all similarly bland. I'm pretty experienced with this sorta' stuff and it doesn't ring wrong to me at all.
Some other stuff.
Checked that moveDirection isn't a huge number
Tried eliminating Time.deltaTime from the equation
Fairly sure colliders aren't ending up inside of the player while a lag spike happens (again, alt-tabbing will do it too)
Geometry surrounding the player is clean (box colliders, mesh colliders on well-developed meshes)
Nothing strange like rapidly setting any components on or off is happening to my knowledge.
Anyone have any experience with this sort of issue? Thanks.