Help with camera/fps game

Hey! I’m trying to make a game like everlife (free on steam) which is basically a fast-paced shooter that is based in all sorts of different dimensions.

Right now I’m trying to figure out how to make the gun part.
This is what I have: https://gyazo.com/392bba55af574dd5f22f36b80eae9f31
Code:

part.Parent = workspace
game:GetService("RunService").RenderStepped:Connect(function()
	part.Shape = Enum.PartType.Cylinder
	part.CFrame = workspace.CurrentCamera.CFrame * CFrame.new(5, -1, -5)
	part.Rotation = Vector3.new(0, -90, 0)
end)

This is what I’m trying to accomplish:

Thanks for any help that I can get. Have a good day!

Don’t create a Part, make a model and CFrame it to that Position.
It looks like you are creating the Rotation in World space, not Object space.

Hey, sorry I don’t really understand how I would accomplish this. I got back to scripting recently, and I would like some help/explanations. Thanks.

You want to rotate the Part (or Model, doesn’t matter) by -90 degrees on it’s Y axis relative to it’s CFrame after being moved, but you’re just setting the Rotation property which is in world space, meaning relative to the world’s XYZ axes. Try

The math.rad stuff is because CFrames use radians and not degrees, and math.rad converts degrees to radians. You could also learn radians and just type -math.pi/2 instead, either is fine.

The * operator between two CFrames means to compute the result of transforming the left CFrame by the right CFrame. CFrame.Angles returns a CFrame with no position, so transforming by it doesn’t move the model but only rotate it. Applying a transform to a CFrame is always in that CFrame’s space, so since you already set the CFrame of the part, the line I modified should rotate the gun 90 degrees to the left, relative to how it’s already rotated.

If I were you though, I would completely delete that line and instead modify the Pivot of the Part (or CFrame, doesn’t matter) so it “naturally” faces forwards.

1 Like