# camera collision not working with spring look?

so i’m trying to get my camera collision to work with spring look, but it’s not doing it for some reason. here’s the function :

``````private void ActivateCameraCollision ( ) {
// Set camera rotation
Quaternion rotation = Quaternion.Euler ( xDeg, yDeg, 0 );
distance = ZoomCamera ( activateZoom );
Vector3 position = target.position - ( rotation * Vector3.forward * desiredDistance + vTargetOffset );
// Check for collision using the true target's desired registration
// point as set by user using height
RaycastHit collisionHit;
Vector3 trueTargetPosition = new Vector3 ( target.position.x,  target.position.y + targetHeight, target.position.z );
// If there was a collision, correct the camera position & calculate
// the corrected distance
bool isCorrected = false;
if ( Physics.Linecast ( trueTargetPosition, position, out collisionHit, collisionLayers.value ) ) {
// Calculate the distance from the original estimated
// position to the collision location,
// subtracting out a safety "offset" distance from the
// object we hit
// The offset will help keep the camera from being
// right on top of the surface we hit,
// which usually shows up as the
// surface geometry getting
// partially clipped by the camera's front
// clipping plane
correctedDistance = Vector3.Distance ( trueTargetPosition, collisionHit.point ) - offsetFromWall;
isCorrected = true;
}
// For smoothing, lerp distance only if either distance wasn't
// corrected, or correctedDistance is
// more than currentDistance
currentDistance = ! isCorrected || correctedDistance > currentDistance ? Mathf.Lerp ( currentDistance, correctedDistance, Time.deltaTime * zoomDampening ) : correctedDistance;
// Keep within standard limits
currentDistance = Mathf.Clamp ( currentDistance, zoomMindistance, zoomMaxdistance );
// Recalculate position based on the new currentDistance
position = target.position - ( rotation * Vector3.forward * currentDistance + vTargetOffset );
transform.rotation = Quaternion.Slerp(rotation, Quaternion.Euler(xDeg, yDeg, 0), Time.deltaTime * damper);
transform.position = position;
}
``````

Any help is GREATLY appreciated!

Uh maybe use Raycast instead of Linecast in line 15?

I dunno, I’m just 9, started Unity few months ago

(Oh btw maybe use multiline comments instead of putting a double slash each time you comment. It makes work a bit easier for me.)

someone can help?