Changing distance to aim target cause LookAt jump/jitter
I have an archer in a third-person camera view. The camera rotates (aims) towards where the bow is pointing + added distance, which works well. I use Raycast to spot targets and shorten the aim distance to that target. Problem: when I change distance to target; the cameras rotation jumps towards the new target position. Is there a way to make the transition smooth using LookAt on the camera?
Bow
code for updating aimTarget:
void FixedUpdate() {
float targetDistance = AIM_DISTANCE;
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, AIM_DISTANCE))
{
targetDistance = Vector3.Distance(hit.transform.position, transform.position);
}
aimAtPosition = transform.position+transform.TransformDirection(Vector3.forward) * targetDistance;
}
public Vector3 getBowTarget()
{
return aimAtPosition;
}
Camera
code for looking at the target (positioning code omitted):
transform.LookAt(bowScript.getBowTarget());
Your answer
Follow this Question
Related Questions
Rotate character body alongside movement. 0 Answers
Hard coded rotation of child results in weird arc rotation when parent is rotated? 0 Answers
Camera rotate X degree based on player rotate 0 Answers
Camera Rotation Switching Problem 0 Answers
Como desplazar la camara en un juego en tercera persona 0 Answers