How do I rotate this gun properly?

Hey :wave:

Today I was working on adding new guns to my gun script, and I ran into an issue with rotation. My original gun, that I got from free models, is positioned fine. But when my friend made me a gun, I started encountering issues with the rotation of the gun in the hand. I tried adding a rotation value into my gun module and then CFraming the guns primary part to that angle, but it didn’t work. I tried rotating the C0 and the C1 but that rotated my fake arms position as well. Any other ways I could handle this?

Gun Pictures

Original Gun

New Gun

Code
local Weapon = ReplicatedStorage.Guns:FindFirstChild(Gun.Name):Clone()

Weapon.PrimaryPart.CFrame = Weapon.PrimaryPart.CFrame * GunInfo["CF"]["Angle"]
Weapon.Parent = ViewModel
ViewModel.Parent = Camera

local Joint = Instance.new("Motor6D")
Joint.C0 = CFrame.new(1, -1.25, -2)
Joint.Part0 = ViewModel.Head
Joint.Part1 = Weapon.Handle
Joint.Parent = ViewModel.Head

I haven’t worked a lot with animations, but wouldn’t you use CFrame.Angles with rotation?

Yes, I just removed that part of code since it did nothing. Added back,

Not entirely sure about this, but try setting Part1 and Part0 before you change C0

Nothing changed :confused:

Try rotating the part by doing

Joint.C0 = CFrame.new(1, -1.25, -2) * CFrame.Angles(0,math.rad(90), 0)

You might need to experiment with it a bit. math.rad() converts degrees into radians, which is probably what you were doing originally. This rotates the y-axis by 90 degrees.

3 Likes

That is what the

GunInfo["CF"]["Angle"]

is. As I’ve said, when I rotate the C0, the part I use to attach the gun also rotates. Let me have a play around with positions though.

Seems to have worked, just rotated the right hand part. Still, I feel like there must be a more efficient way of doing this.

Would you mind posting the place file so that we can interact with the code?

1 Like

Have you tried rotating the Joint.C0 by 90 degrees?
As far as I can see, that’s the Joint which connected Weapon to Handle.

1 Like

Already solved.

In the future, the following plugin by EgoMoose may be useful when working with tools:

The plugin makes it very simple to edit a tools grip.

2 Likes