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.
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
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.
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.
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.
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.