Camera Shake Problem

I have camera that’s position changes by velocity. So camera is shaking with little changes. I try to smooth everything but there is always shake. Is there any solution for this problem. I want that camera is up when my object go down and down when go up.

Positioning code shortly:

positionDesiredCamTemp = transform.position + new Vector3(positionCam.x, positionCam.y - rb.velocity.y * camY, positionCam.z).normalized * positionCam.magnitude;

If you want your camera to follow your object then you can just set your camera’s position to your objects position plus some offset.

[SerializeField] private Vector3 _offset;

// ---

positionDesiredCamTemp = rb.transform.position + _offset;

Then your offset will state where you camera is relative to your object.

If you were trying to add some semblance of sway to your camera’s movement then use inertia:

[SerializeField] private Vector3 _offset;
[SerializeField] private float _inertia = 0.95f;

private Vector3 _previousMovement;

// ---

// where we are trying to get to, like in the previous code snipped
Vector3 targetPosition = rb.transform.position + _offset;

// what our movement would be if we move straight to the target
Vector3 targetMovement  = targetPosition  - transform.position;

// a fraction of the target movement added to a fraction of the previous movement, _inertia being the ratio by which we combine the two
Vector3 inertiaAdjustedMovement = (_inertia * _previousMovement) + ((1f - _inertia) * targetMovement); 

// then use this movement as our actual movement
positionDesiredCamTemp = transform.position + inertiaAdjustedMovement;

// for anything inertia-related, we need to store our previous value to use it in the next update loop
_previousMovement = inertiaAdjustedMovement;

Please let me know if this wasn’t what you’re trying to do or if you need clarification on any of it!

Why don’t you try a SmoothDamp effect, specifically made for smoothing out things like the camera. Here it is in the docs, but I would suggest to put it in LateUpdate() instead of update: Unity - Scripting API: Vector3.SmoothDamp. If you need to follow at an offset, just set an empty child at the offset position and follow the child instead and you can use LookAt() to make sure your rotation stays locked on your subject

Making interpolate and collision detection continous was solved the problem.