- Home /
Targeting character controller
The bottom line is that the character would move around the object with horizontal input. And during the vertical input, the character moved forward.
My code example
Vector3 direction = transform.forward * _moveDirection.y + transform.right * _moveDirection.x;
Vector3 targetDirection = _targetPosition.position - transform.position;
Vector3 rotationDirection = Vector3.RotateTowards(transform.forward, targetDirection, 360, 0.00f);
Quaternion targetRotation = Quaternion.LookRotation(rotationDirection);
float xAngleError = Mathf.DeltaAngle(transform.rotation.eulerAngles.y, targetRotation.eulerAngles.y);
float xTorqueCorrection = _pid.GetOutput(xAngleError, Time.deltaTime);
transform.rotation = Quaternion.Euler(xTorqueCorrection * Vector3.up);
_characterController.Move(direction.normalized * (_walkSpeed * Time.deltaTime));
but due to centrifugal force, the character flies out of the playing field.
Please help me!
Comment