Hi there. I've got a simple scene setup with a player using the third person controller from the 3D Platformer tutorial and an enemy. I've got the code found at the bottom here in a function that a I call in LateUpdate with GetButton so that while I hold the button down, the player "locks on" and continuously faces the enemy while moving around him not unlike various 3D action games like Phantasy Star Online, Devil May Cry, etc.
function Update () {
var waypoints: GameObject[] = GameObject.FindGameObjectsWithTag("waypoint");
var closest: GameObject;
var closestDist = Mathf.Infinity;
for (waypoint in waypoints) {
var dist = (transform.position - waypoint.transform.position).sqrMagnitude;
if (dist < closestDist) {
closestDist = dist;
closest = waypoint;
}
}
transform.LookAt(closest.transform);
}
This works almost perfectly. The problem is, when you let go of the button, the player's facing immediately snaps back to the direction you were moving in. So, for example, if you were locked on and moved away from the enemy then let go of the button, the player's facing immediately snaps away from the enemy. I'm assuming this is because LookAt isn't affecting what the Third Person Controller's using to rotate the character's facing in the direction its moving (moveDirection?), however, I'm unsure as to how to use the enemy's position with the movement direction so that when you let go of the button, the player still faces the enemy at that moment until you move him in a different direction. I'd appreciate any help I could get!