I'm trying to make a tank script that allows you to turn the turret & barrel with your mouse. The turret is a cylinder so it has to move left and right on the y axis. Yes, the y axis. Since the tank is unanchored I am using a weld to CFrame the turret.
I have an example of my tank script at my place. It can be driven. You can press f to fire the machine gun (which is my old script that I need to rewrite.) With all of the crazy things I have tried you'd see that I can't get the barrel to point at the mouse.
This is probably very inaccurate but it would be something similar to this I'm guessing? Just kind of an example of what I have tried.
wait(1) player = game.Players.LocalPlayer mouse = player:GetMouse() weld = findCar.VehicleSeat.Connection -- this is the weld that I need to CFrame while true do wait() weld.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(mouse.Origin.z,0,0) end
I really don't know how to ask this. And I don't really have too much information to give.
Summary of my question: Since the turret rotates left and right on the y axis. How do I make it turn left and right with your mouse by CFraming the weld.
The best place you can look, is the Roblox Developer documentation. If you look at this page you'll notice a nifty attribute of the player's mouse. The hit attribute. According to the docs:
The CFrame of the mouse’s position in 3D space.
So, that means it will give you the CFrame of where the player's mouse is pointing. Now, you simply set your current to rotate, to face that CFrame.
I hope I answered your question.