Cannon rotates into ground (CFrame problem)

There’s 4 buttons next to the cannon that control which direction it rotates (left, right, up, down)

Screen Shot 2022-03-13 at 9.30.30 PM

The problem is that when you rotate it, it slowly turns into the ground

I’m not sure what’s wrong with my code, the lines below are the ones responsible for the rotation (within a tween)

CFrame = part.CFrame * CFrame.Angles(0,math.rad(degrees),0) -- Left/right

CFrame = part.CFrame * CFrame.Angles(0,0,math.rad(degrees)) -- Up/down

Any help would be greatly appreciated, here’s the game if you want to see the issue for yourself:

I have a question, How long does the tween last? my first guess is that it could be some behavior related to the tween being interrupted mid-animation. But a simple solution that ocurrs to me is just resetting the cannon’s orientation in the axis- that you arent using.

Also the game you linked is set to private

1 Like

It should be public, might just be a server thing.

How do I go about doing this?

0.4 seconds

Maybe try enabling the Massless property of all the parts?

It’s a tween so mass is negligible

When I just use the left and right buttons, the cannon doesn’t seem to be unbalanced, however, when I click the up arrow and then proceed to click the left/right arrow afterwards it goes unbalanced…

Is it possible where I could see the whole code?

1 Like

Unfortunately that led to the same issue

At the moment, all my parts are welded to one part that rotates everything. How would I make it so only the gray part moves in that system without cross-welding?

store the rotations in a variable

local vertical = 0 -- Up/down
local horizontal = 0 -- Left/Right

then when you press the button, tween the rotation like this

CFrame = CFrame.Angles(0, math.rad(horizontal), 0) * CFrame.Angles(math.rad(vertical), 0, 0)

You could use WeldConstraints instead as it allows separate parts to be rotated freely whilst welded together unlike Welds.

1 Like

I did not know those existed, that’s what was keeping me from moving the barrel independently from the wheels when I tried making two weld parts. Thanks!

1 Like

I’m not entirely sure if I’m right though, you should try it out before marking my post as solution.

If that doesn’t work… maybe try just changing the Orientation of the grey part when moving up and down.

It is, I read up on it. I’m playing around with it right now in studio and it seems to do the trick.

https://developer.roblox.com/en-us/api-reference/class/WeldConstraint

1 Like

Welds snap when the BasePart instances it welds together are moved. WeldConstraints on the other hand stay intact.

1 Like