Scripting Tip: PopperCam Manipulation / How to have specific objects collide with the camera

Hey folks,

I’ve been recently working on a game that involves a lot of custom and wacky debris. Though the debris parts use differing collision groups from the player, I ran into an issue. I realized that the parts still collided with the camera, which resulted in an abrupt zooming effect if a debris item obstructed the camera’s view.

After different attempts and takes to solving the situation, and after quite a bit of time spent looking into the functionality of the CameraScript, I figured out how to allow specific objects to collide with the camera.

I used a copy of Roblox’s CameraScript to make the needed changes. It’s important to note that you can copy and paste a copy of the CameraScript inside StarterPlayerScripts, and the copy will replace the default CameraScript, which allows us to customize to our desire. I found it easy to go into play test, and copy it from the explorer.

To continue, if you look under the PopperCam Module and at about line 139, you will see two loops that add specific parts to an array called ignoreList. The array, ignoreList, contains a list of parts to ignore when deciding if a part is obstructing the camera. The ignoreList is used in dictating the cut off distance for the camera based on obstructions. If an item is under the list, it is ignored, and the camera does not zoom in if said item is obstructing.

Essentially, to add any parts you’d like to not be an obstruction to the camera but still be opaque and or collidable, you can add a loop to hide a group of objects. For example, if you wanted to have a model be uncollidable with the camera, you could do the following just below the established two loops:

ignoreList[#ignoreList + 1] = workspace.Model

I haven’t seen a solution to this yet, so I figured it would be a helpful to spread the word. I hope this helps!

5 Likes

You could also do

for i, v in pairs(game.Workspace.Model:GetChildren() do
     table.insert(ignoreList, #ignoreList + 1, v)
end

Édit; might’ve gotten arguments wrong for insert, on mobile so I can’t check.

3 Likes

In your model example, just insert the model itself into the ignore list instead of inserting its children one by one. GetLargestCutoffDistance (the method used by PopperCam to determine how far to push the camera forward) ignores the descendants of instances in its ignore list, too.

table.insert() automatically inserts elements at the last index of the array when the position isn’t specified. Just table.insert(ignoreList, v) is fine.

6 Likes

Even better! :smiley:

2 Likes