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

How do I make a model with a primary part face another part?

Asked by 6 years ago

I am trying to make a turret that has a model as its parent rotate towards the direction of the nearest player within 50 studs. Currently I am using a cylinder as the range since my scripting isn't advanced. Here is my current script:

tuching = false

script.Parent.Touched:connect(function(part)
    if part.Name ~= 'Baseplate' and part.Name ~= 'Part' then
        print('touched')
        tuching = true
        wait()
        script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.base.CFrame.p, Vector3.new(0,0,part.CFrame.Z)))
    end
end)

script.Parent.TouchEnded:connect(function(part)
    if part.Name ~= 'Baseplate' and part.Name ~= 'Part' then
        print('no more tuch')
        tuching = false
    end
end)

I am looking for a proper :SetPrimaryPartCFrame() method of facing towards a part with it looking up and down a.k.a without the Y axis.

1 answer

Log in to vote
0
Answered by 6 years ago

There is a way of doing this with :SetPrimaryPartCFrame()! In the second parameter of CFrame.new(), you are able to set where the part will face. Since your model has a primary part, this will make all the parts in the model face the same direction.

local part = Instance.new("Part", workspace) -- Create a part

part.CFrame = CFrame.new(Vector3.new(0, 50, 0), Vector3.new(0, 0, 0)) -- Move part 50 studs up from the origin and make it face towards the origin.

You can achieve the same thing in a model with a primary part by doing:

model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0, 50, 0), Vector3.new(0, 0, 0))
0
Sorry if I didn't completely answer your question, but with what I have said I think you will be able to figure out the rest ;) Operation_Meme 890 — 6y
0
Thank you but I am trying to make it ignore the Y value to prevent it from going up and down and only look from left to right MultipleHeadshots 10 — 6y
0
No problem, if this is what you were looking for, please accept/upvote my answer :) Operation_Meme 890 — 6y
Ad

Answer this question