I’ve got a gun that I’m trying to get to point toward a player, however, because of the way the front face of the cylinder is, it follows the player but in the wrong way. Is there a way to rotate the front face so it isn’t sideways, or adjust for this in the CFrame calculation. I only need to gun to follow on one axis. Here’s what I’ve tried.
-- base refers to the cylinder, and tHumPart to the player's humanoid root part
-- attempt 1
base.CFrame = CFrame.new(base.Position, Vector3.new(base.Position.X, base.Position.Y, tHumPart.Position.Z)) * CFrame.Angles(0, 0, math.rad(90))
-- attempt 2
base.CFrame = CFrame.new(base.Position, Vector3.new(base.Position.X, base.Position.Y, tHumPart.Position.Z))
-- attempt 3
base.CFrame = CFrame.new(base.Position, tHumPart.Position)
In studio, select the cylinder part you’re rotating, under the properties window scroll down to PivotOffset and adjust the rotation values as needed. This will allow you to CFrame the part in your script as you already are, but will automatically apply a rotational offset which you can customize to make it so your model is facing the correct way.
Edit - You’ll also need to use the PivotTo(CFrame) method for this to work
The easiest way to solve your problem would be to do this:
Make an invisible cube that is anchored and as big as the whole turret model
Make sure that the cube’s front face is where you want the front of your turret to be (use ShowOrientationIndicator to do so, or a Decal in the front face)
Unanchor everything else exept the cube, and weld everything to the cube
Instead of rotating the base, we will now rotate the cube like so:
works much better than the formula I gave you so use it for now while I find a way to stop the turret from rotating up and down unless you do want the turret to do so