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

How do I set the CFrame of a moving model without affecting the whole thing?

Asked by 7 years ago

Alright, so I have a tank and whenever I sit in the seat, the barrel of the tank is supposed to always face the mouse. The problem is however, the whole tank moves with the barrel! FYI - The barrrel is welded to the tank, and if I unwelded the barrel, it would just fall off. How can I make the barrel face my mouse and not the rest of the tank?

This is what I used to face the barrel towards the mouse (and the rest of the tank)

function move(target)-- target is basically the mouse.Target
    if script.Parent.Parent:findFirstChild("Hole") and hole:FindFirstChild("BodyGyro") then
    local mp = hole
    local dir = (target - mp.Position).unit
    local pos = mp.Position + (dir*1)
    mp.BodyGyro.cframe = CFrame.new(pos, pos + dir)
    mp.BodyGyro.maxTorque = Vector3.new(9000,9000,9000)
    end
end
1
Use a weld to weld the gun to the tank. Then use the cframe property of the weld to rotate the gun rather than the whole model. AZDev 590 — 7y
0
thank you so much i forgot you can use the weld CFrame !! laughablehaha 494 — 7y
1
No problem AZDev 590 — 7y

Answer this question