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

Need help with :SetPrimaryPartCFrame() [?]

Asked by 6 years ago

So I'm experimenting with SetPrimaryPartCFrame(), trying to make some remote controlled gun but having issues.

As far as I know, a CFrame value includes: Position, Orientation. That's one confusing thing and that's what I've done.

I want to make the remote controlled gun stay in it's position but rotate to the camera.

So I'm doing CIWS:SetPrimaryPartCFrame(CIWS:GetPrimaryPartCFrame().p, Camera.CFrame.lookVector)

the entire script that moves the gun is this:

RunService.HeartBeat:connect(function() workspace.CIWS:SetPrimaryPartCFrame(CIWS:GetPrimaryPartCFrame().p, Camera.CFrame.lookVector) end)

But no, I get this: The gun moves a bit from it's start position and it doesn't rotate.

Did i miss something or 'am i doing this completely wrong?

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago

You have to construct a new CFrame inside of the SetPrimaryPartCFrame() function instead of providing two separate arguments. In addition, the look vector must be set to the camera's position and not the look vector because you want the gun to be rotated towards the camera's position and not its look vector. So in order to correctly set the CFrame of the gun you can do this:

RunService.HeartBeat:Connect(function ()
    local lookVector =  Camera.CoordinateFrame.p
    local posVector = workspace.CIWS:GetPrimaryPartCFrame().p
    local cf = CFrame.new(posVector , lookVector)
    workspace.CIWS:SetPrimaryPartCFrame(cf)
end)
0
Lmao thanks but i made a mistake, you are aiming at the camera, not where the camera is pointing to, oh wait i should use mouse Ashley_Phantom 372 — 6y
Ad

Answer this question