Scripting Helpers is winding down operations and is now read-only. More info→
Log in to vote

How do I rotate an object on one axis?

Asked by 7 months ago
Edited 7 months ago

So I have been making this Dead Space Plasma Cutter type thingy and I ran into this issue where I have been trying to rotate the blades of the gun on one axis while all the other axis' aren't affected (or actually rotate). I don't know how to make this work so any and all help will be largely appreciated.

All code and sources are below to get an easier understanding of what I'm trying to accomplish.

For quick clarity I'm using a mesh part, Blades, that welds every part that's supposed to rotate upon pressing the space key. And that mesh part is motor6D welded to the Handle mesh part.

The hierarchy:

Code I have been using to rotate the 'Blades':

local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")

local plasmaCutter = script.Parent
local handle = plasmaCutter:WaitForChild("Handle")
local blades = plasmaCutter.Blades.Blades

    if input.KeyCode == Enum.KeyCode.Space then
        local currentRot = blades.Orientation
        local targetRot =, currentRot.Y, currentRot.Z - 90)
        TS:Create(blades,, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Orientation = targetRot}):Play()
        print("Alt fire!")

What it should look like (while being able to move ofc):

The problem:

1 answer

Log in to vote
Answered by 7 months ago
Edited 7 months ago

Welp, I figured it out! All I did was change the hierarchy a bit to have another part basically holding the position of the blades. Then I changed the code to this:

-- Creating a new Moter6D joint to rotate the blades on one axis
local bladeJoint ="Motor6D")
bladeJoint.Part0 = blades
bladeJoint.Part1 = rotPoint
bladeJoint.Name = "BladeRotation"
bladeJoint.C0 =
bladeJoint.C1 =
bladeJoint.Parent = blades

local rotated = false -- Checking to see if the Plasma Cutter has already been flipped when alt-fired

    if input.KeyCode == Enum.KeyCode.Space and rotated == false then
        rotated = true

        local currentRot = bladeJoint.C0
        local targetRot = currentRot * CFrame.Angles(0, 0, math.pi/2) -- Using CFrame calculations to rotate the blades 90 degrees to the right
        TS:Create(bladeJoint,, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {C0 = targetRot}):Play()
    elseif input.KeyCode == Enum.KeyCode.Space and rotated == true then
        rotated = false

        local currentRot = bladeJoint.C0
        local targetRot = currentRot * CFrame.Angles(0, 0, -math.pi/2) -- Also using CFrame, but to rotate the blades 90 degrees back to the left
        TS:Create(bladeJoint,, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {C0 = targetRot}):Play()

adding a Motor6D element in conjunction with CFrame. Finally achieving the animation with no weird rotations!


Answer this question