How can I make my custom camera collision smoother?

Hello, I was currently trying to test out my camera and noticed that the collisions transition a bit too harsly… How can I make this look smoother without cliping into the parts?


Thanks in advance!

2 Likes

You could keep the camera clipping but only as it returns back to it’s original distance and make it snap when it’s occluded.

You can use the Raycast API in roblox to create the smooth movement collision.
By like checking if there are any obstacles between the camera and the player.

Thats honestly a decent solution but the snapping is honestly killing me :sob::sob:

1 Like

i am using the raycast api its just the snapping of the collisions thats making me cry my brain out :broken_heart:

3 Likes

You could try shooting a couple rays to the next predicted camera spots, and only clamp to the closest surface among all the results

There’s no other alternative solution to your problem.

You could do something like:

Camera_Distance = math.min(rayDistance,
     math.lerp(Camera_Distance,Expected_Camera_Distance,Delta_Time*10))

Yeah but wont it like clip inside the objects?

No because it would snap if the camera clips but would ease back out if the camera doesn’t clip.

It’s hard to explain but logically:

Camera clips > Camera Snaps.
Camera doesn’t clip > If camera distance is less than the expected distance then camera eases to the expected camera distance, else no change occurs.

This way it would snap only when it’s obstructed and eases back out when it’s not obstructed.

Oh yeah I see, mb I just read the code wrong. But thanks though!
And also, if you find a way to remove the snapping at the start of the collision. Please tell me, I really need it :sob::sob::sob:

Ehh it’s a bit tough but I’ll let you know tomorrow.

1 Like

I may have found a solution!


(Taken from my personal project.)

As seen in the video, the character’s camera occlusion is more interpolated

Here’s the piece of code that actually handles this.

local Origin = -- Camera origin with respect to (w.r.t) the shoulder distance.
local OcclusionRay = Functions.BlockCast(Origin.Position,-Camera.CFrame.LookVector*Camera_Distance,Vector3.one*3)
if OcclusionRay then
	Camera_Eased_Distance = math.lerp(Camera_Eased_Distance,OcclusionRay.Distance,deltaTime*12)
else
	Camera_Eased_Distance = math.lerp(Camera_Eased_Distance,Camera_Distance,deltaTime*10)
end

I had actually thought of this while I sent my previous message, I was just too busy to explain it to you haha. :heart:

2 Likes