Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I get a part to rotate in the direction of the camera on only two axes?

Asked by
Reivani 11
5 years ago

Hi! I'm making a particle script using parts and I'm trying to make the parts follow the position of the camera but only allowing the parts to rotate on the X and Z axis, so if the player looks up in first person the particles won't rotate facing the player, if that makes sense.

local tweenService = game:GetService("TweenService")
local cam = workspace.CurrentCamera
local rand = math.random
local num = 100
local part = workspace.Part

game:GetService("RunService").Stepped:Connect(function()
    local clone = part:Clone()
    clone.CFrame = cam.CFrame + Vector3.new(rand(-num, num), 0, rand(-num, num))) --How would I make the cam.CFrame part only rotate on the X and Z axis? (the vector3 is to randomize the position of the particles)
    clone.Parent = workspace
    local tweenInfo = TweenInfo.new(0.75,
        Enum.EasingStyle.Linear)
    local tween = tweenService:Create(clone, tweenInfo, {CFrame = clone.CFrame + Vector3.new(0,25,0)})
    tween.Completed:Connect(function() clone:Destroy() end)
    tween:Play()
end)

I've tried

clone.CFrame = CFrame.new(Vector3.new(cam.CFrame.Position.X, 0, cam.CFrame.Position.Z) + Vector3.new(rand(-num, num), 0, rand(-num, num)))

But that only moves the particles positions on the X and Z axis, not its rotation.

Answer this question