Custom camera - seeing through CanCollide false parts?

I’ve been making a custom camera, and I’m wondering how I’d detect whether a part is collideable or not so I could see through it with the camera. The default Roblox camera allows people to do this - but I can’t seem to find out how. Does it raycast again when it’s found the part in the way of the camera is CanCollide false, and continue that? Is this not expensive to do every frame?

If you can help, I’d appreciate it very much. Thank you.

3 Likes

Does it raycast again when it’s found the part in the way of the camera is CanCollide false, and continue that?

Yes, this would be the best way to do it. Stick the Raycast in a repeat loop that adds any CanCollide-false parts it hits into an ignore list until the ray hits either nothing or a solid object.

1 Like

Alright, thought so. Feels a bit awkward but I’ve heard raycasting isn’t all that expensive. Thanks!

2 Likes

Check out GetLargestCutoffDistance. It automatically ignores parts that are non-collidable. I learned this on accident a week ago. I imagine this is the proper way to do this.

Note: You must assign the Focus property of the camera in order for this to properly work.


The logic to using this method is the following:

  1. Set the camera where it should probably be (without figuring out if parts are in the way yet). Set the Focus at the point of which the camera is looking (e.g. the character’s head). This has to be a CFrame value, but I think it just cares about the position, not rotation.
  2. Run GetLargetCutoffDistance.
  3. If it returns non-0, then move the camera forward based on this number.
5 Likes

Ooh, I’ll try this. I’m not even using a Focus point right now - I’m new to this camera stuff. Thanks you, will update you on whether or not it works.

2 Likes

In Scriptable mode, Focus doesn’t actually change what the camera looks at–that’s still controlled by the CFrame property. But you still have to set the focus in order for the method to work. I always just set it to the character’s head CFrame.

3 Likes

This works. Thank you.

3 Likes