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

How to rotate a part to face a brick?

Asked by 6 years ago
Edited 6 years ago

Alright, I already know how to do it, but I have a weird issue when I rotate the brick to face the part in question. The video of the problem is here: https://youtu.be/dgF7W9D8kEY The problem is that the part I want to turn moves off the base of the turret which looks really bad. How could I fix it? The script is as follows:



function FindClosestPerson() for _,v in pairs(game.Players:GetChildren()) do if v.Character:FindFirstChild("Torso") ~= nil and v.Character:FindFirstChild("Humanoid") ~= nil and v.Character.Humanoid.Health > 0 then if (v.Character.Torso.Position - script.Parent.Union.Position).magnitude <= 20 then if v:GetRankInGroup(2874380) < 255 then return v.Character.Torso end else return nil end end end end function NoTarget() script.Parent:SetPrimaryPartCFrame(script.Parent.Part.CFrame * CFrame.fromEulerAnglesXYZ(0,0.01,0)) end function Aim(TargetTorso) script.Parent.Union.CFrame = CFrame.new(script.Parent.Union.CFrame.p,TargetTorso.CFrame.p) end while true do local TargetTorso = FindClosestPerson() wait() print(TargetTorso) if TargetTorso == nil then NoTarget() else Aim(TargetTorso) end end

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago

Rather than rotating the union, weld it to a Cylinder part that has the radius of rotation you desire. Rotate said cylinder.

0
Thanks! jhunlzeus4 20 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Make the thing you want to rotate a model, and place a invisible part at the bottom. The turret will rotate on the center of this part. Now go to the model's properties, and find PrimaryPart. Set this to the invisible part on the bottom of your model. Now here's what I use to rotate models, it's not my scripting, forgive me if it's not efficient:

local model = workspace.model --The model of the turret
model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(45), 0)) -- This rotates the model 45 degress

Accept if this helped

0
Thanks, I just don't know how to use PrimarypartCFrame to face the torso, it could be done somehow I am sure though, I appreciate it! jhunlzeus4 20 — 6y

Answer this question