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':
01 | local UIS = game:GetService( "UserInputService" ) |
02 | local TS = game:GetService( "TweenService" ) |
04 | local plasmaCutter = script.Parent |
05 | local handle = plasmaCutter:WaitForChild( "Handle" ) |
06 | local blades = plasmaCutter.Blades.Blades |
08 | UIS.InputBegan:Connect( function (input) |
09 | if input.KeyCode = = Enum.KeyCode.Space then |
10 | local currentRot = blades.Orientation |
11 | local targetRot = Vector 3. 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() |
What it should look like (while being able to move ofc):
https://gyazo.com/55d733a945b9ed5afe6737f46709162a
The problem:
https://gyazo.com/1b92741704ff49ee36d496feb53da891