Hi guys, I have recently experienced an issue where my player teleports on the upper side of the Enemy whenever it gets too close. I have no idea why it is occurring though.
Regarding the setup: My player has a Character controller and a rigidbody (kinematic) components; the enemy has a Navmesh, a mesh collider and a rigidbody (kinematic) components.
I worked on fixing it by turning the mesh collider into convex and turning ‘is kinematic’ off. That seems to work but I need to keep the mesh collider without it being convex, since my enemy is a donut and you have to be able to shoot through its hole. Some forums suggest that changing the height of the Navmesh Agent may be able to fix it, but it doesn’t seem to be the case. It doesn’t work changing the Character Controller slope limits either. I tried reducing the slope limit and the step offset to 0 but it didn’t work. I would really appreciate some help. (this video shows the issue: Issue - YouTube)
Try to make like this in the enemy object on set position:
float rangeToAttack = 2f;
.......
if(Vector3.Distance(Player.transform.position, Enemy.transform.position)>rangeToAttack)
{
// set posisition
}
Hope it help.