Hello,i’m making GMOD like game. So i need help with camera direction and the distance to where is the camera looking at.(srry my english isn’t that good)
local RS = game:GetService(“ReplicatedStorage”).SpawnLists
local spawnButton = script.Parent
local Players = game:GetService(“Players”)
spawnButton.MouseButton1Click:Connect(function()
local Humanoid = Players.LocalPlayer.Character:FindFirstChild(“HumanoidRootPart”)
local object = RS.Part:Clone() --edit the “object” to serverstorage name.
object:PivotTo(Humanoid.CFrame * CFrame.new(1,5,-10)) – you can edit this for how far the cloned object are away from the player.
object.Parent = game.Workspace.Clones
i want to make when the part cloned i need the part to spawn on where is tha character looking at. ect: hes looking at the wallk then the part is spawns on wall
uhh do you wanna do this in a server script or a local script?? because if its local you can just do game.Players.LocalPlayer:GetMouse().Hit.Position to get the position and from there you can get the direction and length from (game.Players.LocalPlayer:GetMouse().Hit.Position - workspace.CurrentCamera.CFrame.Position).Unit-- for direction and (game.Players.LocalPlayer:GetMouse().Hit.Position - workspace.CurrentCamera.CFrame.Position).Magnitude – for length
spawnButton.MouseButton1Click:Connect(function()
local Humanoid = Players.LocalPlayer.Character:FindFirstChild(“HumanoidRootPart”)
local object = RS.Part:Clone() --edit the “object” to serverstorage name.
local ray = workspace:RayCast(Camera.CFrame.Position,Camera.CFrame.LookVector*1024)
local Position = ray.Position
object:PivotTo(CFrame.new(Position)) – you can edit this for how far the cloned object are away from the player.
object.Parent = game.Workspace.Clones
end)
We aren’t allowed to give complete scripts but because you are a noob then ok.
the way @awry_y did it here is the best if you want it to be adjucsted to the camera’s perspective but ill give you another version where it moves to your mouse.
local Humanoid = Players.LocalPlayer.Character:FindFirstChild(“HumanoidRootPart”)
local object = RS.Part:Clone() --edit the “object” to serverstorage name.
local mousepos = game.Players.LocalPlayer:GetMouse().Hit.Position
object:PivotTo(CFrame.lookAt(mousepos, Humanoid.Position))
object.Parent = game.Workspace.Clones
end)