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

How do I rotate an object on one axis?

Asked by 2 years ago
Edited 2 years 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: https://gyazo.com/0f3c23304baddf2b0dcac5a90d471f82

https://gyazo.com/79abfd4ac96598ea10d1d95a36a66524

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

01local UIS = game:GetService("UserInputService")
02local TS = game:GetService("TweenService")
03 
04local plasmaCutter = script.Parent
05local handle = plasmaCutter:WaitForChild("Handle")
06local blades = plasmaCutter.Blades.Blades
07 
08UIS.InputBegan:Connect(function(input)
09    if input.KeyCode == Enum.KeyCode.Space then
10        local currentRot = blades.Orientation
11        local targetRot = Vector3.new(currentRot.X, currentRot.Y, currentRot.Z - 90)
12        TS:Create(blades, TweenInfo.new(0.1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Orientation = targetRot}):Play()
13        print("Alt fire!")
14    end
15end)

What it should look like (while being able to move ofc): https://gyazo.com/55d733a945b9ed5afe6737f46709162a

The problem: https://gyazo.com/1b92741704ff49ee36d496feb53da891

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years 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:

01-- Creating a new Moter6D joint to rotate the blades on one axis
02local bladeJoint = Instance.new("Motor6D")
03bladeJoint.Part0 = blades
04bladeJoint.Part1 = rotPoint
05bladeJoint.Name = "BladeRotation"
06bladeJoint.C0 = CFrame.new()
07bladeJoint.C1 = CFrame.new()
08bladeJoint.Parent = blades
09 
10local rotated = false -- Checking to see if the Plasma Cutter has already been flipped when alt-fired
11 
12UIS.InputBegan:Connect(function(input)
13    if input.KeyCode == Enum.KeyCode.Space and rotated == false then
14        rotated = true
15 
View all 26 lines...

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

https://gyazo.com/fef01151b819e7f50cffebd42c687547

Ad

Answer this question