- Home /
Question by
nabil123789 · May 07, 2020 at 06:22 AM ·
camerarotationcharactercontroller
Camera lock on enemy
Hi. I have a problem when I try to lock on target(enemy) camera rotates in wrong direction. // Problem camera's parent lock on enemy and player moves around it, however camera not behind player
public void MoveArroundEnemy(Vector3 enemyPosition)
{
var horizontalAxis = Input.GetAxis("Horizontal");
var verticalAxis = Input.GetAxis("Vertical");
var camera = Camera.main;
var forward = camera.transform.forward;
var right = camera.transform.right;
forward.y = 0f;
right.y = 0f;
forward.Normalize();
right.Normalize();
var desiredMoveDirection = forward * verticalAxis + right * horizontalAxis;
desiredMoveDirection = Vector3.ClampMagnitude(desiredMoveDirection, 1f);
_animator.SetFloat("ForwardSpeed", _speed);
transform.LookAt(enemyPosition);
_followCamera.transform.LookAt(enemyPosition); // Problem camera's parent lock on enemy and // player moves around it, however camera not behind player
transform.Translate(desiredMoveDirection * _speed * Time.deltaTime, Space.World);
}
Comment