Hi There,
I am working on a third person camera game,as the player moves the camera follow the player.I want to rotate the camera on swipe while player is moving(Walk/Run) from one point to another.
While following from one point to another if I simply rotate camera on swipe it gives some jittering and fluctuations.
How we can simply provide swipe rotational effect smoothly while camera is following the player movement?
This is the code snippet from my player follow script:
void LateUpdate () {
if(target == null)
{
return;
}
//ZoomCameraandkeepthedistancebetween [minDistance, maxDistance].
if(Input.touchCount == 2 && pinchZoom)
{
Vector2touch0 = Input.GetTouch(0).position;
Vector2touch1 = Input.GetTouch(1).position;
floatdistance = Vector2.Distance(touch0, touch1);
//Checkprevdistanceandzoominorout.
if(prevDistance != 0)
{
if(prevDistance - distance > 0)
{
verticalHeight+=Time.deltaTime*zoomSpeed*4f;
verticalHeight=Mathf.Clamp(verticalHeight,0.3f,3.6f);
startingDistance+=Time.deltaTime*zoomSpeed;
if(startingDistance>maxDistance)
startingDistance=maxDistance;
}
elseif(prevDistance - distance < 0)
{
verticalHeight-=Time.deltaTime*zoomSpeed*4.2f;
verticalHeight=Mathf.Clamp(verticalHeight,0.3f,3.6f);
startingDistance-=Time.deltaTime*zoomSpeed;
if(startingDistance<minDistance)
startingDistance=minDistance;
}
}
prevDistance = distance;
}
else
{
prevDistance = 0;
}
//Calculatethecurrentrotationangles
floatwantedRotationAngle = target.eulerAngles.y;
floatcurrentRotationAngle = myTransform.eulerAngles.y;
//Damptherotationaroundthey-axis
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
//Converttheangleintoarotation
QuaternioncurrentRotation = Quaternion.Euler (camXAngle, currentRotationAngle, 0);
}
I also have a pinch to zoom function for the player’s position on ground.
Any help will be appreciated.