How can I find if the camera collides with a part?

I’m sorry but it’s still not working… i’m still stuck in the baseplate. Here is my code so far:

function doFunction(dt)

local move = Vector3.zero
for _, v in pairs(activeDirections) do
move += v
end

if move ~= Vector3.zero then
	speedBonus += 0.1
	else
	speedBonus = 0
end

local speed = if shiftPressed then SHIFT_SPEED else MOVE_SPEED + speedBonus

local char = player.Character
local head = char.Head

position += sphere.Position - position + angle * (move * speed * dt)

local cameraCFrame = angle + position
	
--- Do collisions here

sphere.AlignPosition.Position = cameraCFrame.p --move the sphere to that position
cameraCFrame = cameraCFrame - cameraCFrame.p + sphere.CFrame.p --replace with new position
camera.CFrame = cameraCFrame --move the camera to the new position
		
end

Thanks for your help so far by the way.

I really don’t know what could be wrong as that should work. Can you screenshot where script is, where sphere is and what is inside of it. Also what are all the properties of the sphere and AlignPosition you have changed, and can you send the full code within the script? If none of those are the issue then something else might be messing with it.

The script is a localscript under StarterGui, and parented inside the script is a sphere that is massless, unanchored, and has AlignPosition under it. Maybe I will try to use Roblox’s freecam instead? Thanks.

EDIT: AlignPosition is just the default one I think, except it’s OneAttachment

1 Like

No need to use roblox’s freecam if this one has features you need. Do you have an Attachment inside of the sphere that Attachment0 of AlignPosition is set to?

No, I do not. Right now there are no attachments, just a position. Where should I set the attachment to, on top of the sphere or in the middle? Thanks.

Just add an attachment to the sphere, it defaults to middle. And then set the Attachment0 of the AlignPosition to that attachment.

2 Likes

Thank you, it works great now. This is exactly what I needed. Plus you solved a community-interest problem so congratulations. :smiley: Thanks again.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.