Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to wake a rotating part script, similar to the way you inspect a gun in Phantom Forces?

As explained in the title I am working on a game that requires that kind of part rotation (click+drag to rotate) as a main mechanic. I don't require that the script be created, that is against the rules i believe, I just want to know where to start and where to look for more info.

1 comment

0

look for youtube tutorials for an idea

3 answers

OR!!!!

You can make the object's position/CFrame the mouse.Hit.p right?

Here's a quick example:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Object = --bla bla bla
Mouse.Changed(function())
Object.Position = Mouse.hit.p
end)

Haven't tested it out but I am pretty sure it might work.

You can also use UserInputService(UIS) for the rotation part.

another example:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input))
if input.KeyCode == Enum.KeyCode.R then // You can change R to whatever you want
Object.Orientation = Object.Orientation + Vector3.new(0,0,0)--Change the number to your amount!
end
end)
UIS.InputEnded:Connec(function(input))
if input.KeyCode == Enum.KeyCode.R then
return
end
end)

3 comments

0

That's by clicking. Not dragging. And that's position. He wants rotation.

0

I was just going to make the rotation part, just let me continue

0

not sure about the InputEnded part though.

Try checking out this tutorial on YouTube. It should help you.

https://www.youtube.com/watch?v=NSvBg7IYe7g

6 comments

0

Could've been a comment, plus the video is quite old

0

Oh well. Doesn't really matter. There are new ones, old ones.

0

close, but not quite what I was thinking of more like how the camera moves or how you can rotate an object in a 3d program keeping the mouse still while being able to rotate the object in all directions.

0

Look on YouTube for a tutorial. I didn't actually watch that so I had no idea it was Camera Manipulation.

0

It actually does matter, old videos tend to not work in FilteringEnabled and have a ton of deprecated code.

0

^

You need to first figure out when the mouse button is held down and when it is released:

local down, mouse = 0, game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
	down = true
end)

mouse.Button1Up:Connect(function()
	down = false
end)

while true do
	wait()
	if down then
		--Insert rest of code that captures position/direction of mouse and rotates the object accordingly.
	end
end

Create the rest of the code in that if the mouse is moving to the left then the object rotates to the left. If the mouse moves up then the object rotates up. The same for moving to the right and moving down.

This discussion is preserved as it was. New answers, comments, and votes are closed.