How could I go showing the Player Body in first person with offset without clipping through walls

So I have tried looking at various ways to show my Characters body in first person, but they all looked like this:

This is honestly very nonoptimal for me. I have found a way that offsets the camera and locks it to the head, but this allows your camera to clip through walls:

local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')
local RS = game:GetService('RunService')
local camera = workspace.CurrentCamera

local ignoreList = {"Handle", "Head", "HumanoidRootPart"}

RS.RenderStepped:Connect(function(Render)
	local isInFirstPerson = (Character:WaitForChild("Head").Position - camera.CFrame.Position).Magnitude < 1

	for index, desc in pairs(Character:GetDescendants()) do
		local isItemIgnored = table.find(ignoreList, desc.Name)
		local isPart = desc:IsA("BasePart")

		if isPart and not isItemIgnored then
			print(desc.Name)
			desc.LocalTransparencyModifier = 0
		end
	end
end)

Can someone help me out with this?
And yes, I have looked all over devforum for a solution

You could add a small part in front of the character to sort of increase the hitbox. I believe a bunch of games do this. This prevents the player from getting too close to the wall to clip.

2 Likes

Again, I am not a scripter when it comes to working with cameras…so I might need more info on how to do this

Make body parts non collidable?
Perhabs changing collision group if its hardcodded into humanoid behavior.

Also please avoid using localtransparencymodifier and make custom camera system for example if you can.

Avoid using ipairs/pairs and use generic iteration instead like for i,v in tablehere

Turn ignoreList into dictionary

local ignoreList = {Handle=true, Head=true, HumanoidRootPart=true}
local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')::Humanoid
local head = Character:WaitForChild("Head")::BasePart
local RunService = game:GetService('RunService')
local camera = workspace.CurrentCamera

local ignoreList = {Handle=true, Head=true, HumanoidRootPart=true}

RunService.PreRender:Connect(function(Render:number):()
	--local isInFirstPerson = (head.Position - camera.CFrame.Position).Magnitude < 1

	for i,v in Character:GetDescendants() do
		if ignoreList[v.Name] then continue end
		if not v:IsA("BasePart") then continue end
		
		print(v.Name)
		v.LocalTransparencyModifier = 0
	end
end)

And tbh i would’ve instead setted properties of each limb dirrectly for better optimization

1 Like

Well, you could have a character handler script in ServerScriptService (I have this in ALL my projects :P). Here you would create a part using Instance.new("Part"), change the part’s size, and set the transparency to 1. Then, you would create a weld with Instance.new("Weld") and set the C1 to something like CFrame.new(Vector3.new(0, 0, part.Size.Z)). Next, you would set the Part0 property to the character’s HumanoidRootPart and Part1 to the newly created part. After all of this, you would parent the weld to the part, and parent the part to the HumanoidRootPart.

2 Likes

mb i misread the post‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

Clearly, you did not read the complete post. Doing that would result in

when the player attempts to look through walls.

Edit: All good! Thanks for realising that!

1 Like

So I am basically just welding a part to the character?

Yes. Also, make sure the part is massless. I forgot to mention that. There are alternative methods involving some math, like calculating the angle of camera rotation to ensure that it will not clip. If you are interested in that, I can help you out with that.

Camera anti-clip - Help and Feedback / Creations Feedback - Developer Forum | Roblox

Edit: Do note, it may be an unnecessarily extensive amount of work and may not feel as good as simply having a collision part. It is cool, though.

Right, I am not trying to get too complex here.

How even would I now add the camera to that

I’m assuming you would like to avoid the math and stick with the collision part? You don’t need to change the camera’s CFrame at all for this! No math, yay! You would just follow the steps that I listed in my previous post. One thing to add, you might want to create a NoCollisionConstraint between the HumanoidRootPart and the newly created collision part.

1 Like

What exactly do you mean by adding a NoCollisionConstraint?
I’ve never really used them before unless your talking about CollisionGroups?
But yes, I do want to keep it simple.

[spoiler]i haven’t looked at devforum for a while to save my sanity[/spoiler]

A NoCollisionConstraint is an instance that removes collisions between 2 objects. Basically like CollisionGroups, but super easy to set up and really convenient when you’re only removing collisions between 2 objects! It saves the struggle of CollisionGroups.

1 Like