Hello. I am trying to get my turret to rotate to wherever the players mouse is pointing. I’ve tried achieving it and sorta worked but sorta not.
Explorer:
Basically the script below technically works but it rotates the whole tank due to welds. Now at the start of the game the tank is welded in the Framework script to keep the tank from falling apart. But i’m guessing that these welds are making it so the whole tank is rotated when i move my mouse.
LocalScript (Tank.LocalScript)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local TurretUnion = game.Workspace.M4Sherman.BodyKit.Turret.PrimaryPart
while wait() do
TurretUnion.CFrame = CFrame.new(TurretUnion.Position, mouse.Hit.Position)
end
if you want to have something stay in position but not weld it the best thing to do is probs attach a function to renderstepped via the run service.
This mean that at the start of every frame before it is drawn this function will run.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local TurretUnion = game.Workspace.M4Sherman.BodyKit.Turret.PrimaryPart
local M4Sherman= game.Workspace.M4Sherman.PrimaryPart
local Connection = game:GetService("RunService").RenderStepped:Connect(function()
TurretUnion.CFrame = CFrame.new(M4Sherman.Position+vector3.new(offsetx, offsety,offsetz), mouse.Hit.Position)
end)
-- then when you want this behaviour to stop
Connection:Disconnect()
umm you want all the body parts welded to the primary body part
you want all turret parts welded to the main turret part
then you want the turret part hinged to the body part
I’ve never used hingeconstraint before so I’m sorry for any mistakes i make. I’ve put attachment0 to the attachment in the turret primpart and attachment1 to an attachment in the mainpart.
@PotatoVampire7797
Hello. I am currently running what I have in my previous post but its still glitching weirdly the whole tank flyes under the map and its a weird situation. Can you help?
umm i can only guess you got attachemnt 0 and attachment 1 on your welds and constraints backwards somewhere… Im pretty sure this is what causes the randomly fly into the air physics bug. best to check Documentation for the correct way round to do it.