I am trying to make a sort of 'fog' in my game by using an inverted sphere and having it attached to the players camera so i don't have to use any physics.
The problem I am running into is that the parts after they are made no longer update their position, so they are just in one spot. How do i make it so they are always attached to the player's position?
Here is the code:
Player = game.Players.LocalPlayer Character = Player.Character or Player.CharacterAdded:wait() wait() hrp = Character:FindFirstChild("HumanoidRootPart") --creating the fog fogholder = Instance.new("Part", game.Workspace.CurrentCamera) fog = Instance.new("SpecialMesh", fogholder) fogholder.Anchored = true fogholder.CanCollide = false fogholder.Size = Vector3.new(0,0,0) fogholder.BrickColor = BrickColor.new(255,255,255) fogholder.CFrame = CFrame.new(hrp.Position.X, hrp.Position.Y, hrp.Position.Z) fog.MeshId = "http://www.roblox.com/asset/?id=1185246" fog.MeshType = "FileMesh" fog.Scale = Vector3.new(-250,-250,-250)
Also, I don't want the fog to rotate at all.
This one would be quite simple, just use a loop! For example, you could do...
--... while hrp.Parent do --stop once character (or just HRP) despawns --update position fogholder.CFrame = CFrame.new(hrp.Position.X, hrp.Position.Y, hrp.Position.Z) --wait for next 2 frames (default) wait() end
Although it's by no means the only way to do it, you could bind it to RenderStepped or the like, go wild.
--EDIT: Here's how you could do just that, although it involves a tad more lines.
--NOTE: Untested. local RS=game:GetService"RunService" --get RunService local updateFog=function() if not hrp.Parent then --Char is gone! OH NO! RS:UnbindFromRenderStep("UpdateFog") return end fogholder.CFrame = CFrame.new(hrp.Position.X, hrp.Position.Y, hrp.Position.Z) end --Call the function right before the camera updates, for example RS:BindToRenderStep("UpdateFog", Enum.RenderPriority.Camera.Value - 1, updateFog)
See these articles for a little more reference.
https://developer.roblox.com/en-us/api-reference/function/RunService/BindToRenderStep
https://developer.roblox.com/en-us/api-reference/function/RunService/UnbindFromRenderStep