- Home /
Question by
Sannerex · Apr 06, 2018 at 02:14 AM ·
cameracamera-movementsmoothing
Trouble with logic related to my camera smoothing
I'm having trouble with the logic related my camera. I'm trying to make the camera smoothly transition between an "aiming mode" and a "regular mode" based on player input. I don't want the camera smoothed when the camera has finished smoothing. Here is the related
/// <summary>
/// Sets the camera position based on whether or not the player is in aiming mode.
/// </summary>
void HandleCameraMovementBasedOnMode(bool isInAimingMode)
{
// Camera is where it is wanted for aiming
if(isInAimingMode == true && camIsInDesiredAimPos == true)
{
desiredPos = target.position - transform.forward * aimingDstFromTarget + Vector3.up;
transform.position = desiredPos;
}
// Cam is not where we want it for aiming
else if(isInAimingMode == true && camIsInDesiredAimPos == false)
{
desiredPos = target.position - transform.forward * aimingDstFromTarget + Vector3.up;
Vector3 smoothVector = Vector3.SmoothDamp(transform.position, desiredPos, ref posTransSmoothVelocity, posTransSmoothTime);
transform.position = smoothVector;
camIsInDesiredAimPos = true;
}
// Cam is not where it's wanted for normal mode
else if(isInAimingMode == false && camIsInDesiredAimPos == true)
{
desiredPos = target.position - transform.forward * normalDstFromTarget;
Vector3 smoothVector = Vector3.SmoothDamp(transform.position, desiredPos, ref posTransSmoothVelocity, posTransSmoothTime);
transform.position = smoothVector;
camIsInDesiredAimPos = false;
}
// Cam is where we want it when not aiming
else if(isInAimingMode == false && camIsInDesiredAimPos == false)
{
desiredPos = target.position - transform.forward * normalDstFromTarget;
transform.position = desiredPos;
}
}
Comment