I can’t seem to figure this out. I have the stopping distance set to 1.5 so my AI stops, but when he does he stops rotating towards the target allowing the player to closely sneak behind the enemy without him rotating to the player. This makes it easy for the player to do this with large groups of enemies exploiting the game, due to a ranking system with XP and emblems.
This is written in JS.
I know I can use NavComponent.updateRotation = true but that doesn’t seem to work. I tried a custom rotation, look at function, but that doesn’t seem to work either.
var dir = target.position - transform.position;
dir.y = 0; // keep only the horizontal direction
var rotation = Quaternion.LookRotation(dir);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
This is only called when the player is within the attack distance of about 3. How can I get the enemy to always rotate towards the player/target?
I would post the code here but I’m not aloud to. There is nothing wrong with the code itself it’s just a working rotate towards function I’m looking for that works with NavMesh.
I’m also using a rigidbody on the enemy to give him gravity. Could this be causing an issue? If anyone could point me in the right direction it would be greatly appreciated. I’m only here as a last resort because I can’t seem to get it working myself.
Thanks in advanced.