I’m trying to make a mechanism where the arm of my custom character rotates relative to the cursor. So for example if you make a circle with your cursor the arm also rotates 360°. The arm is a model and consists of multiple parts. Here’s an example drawing (sorry for my bad drawing):
Are you looking to make this for R6 or R15?
No, it’s a custom character (which is a spider) and consists of alot of parts, where the arm has 4 parts. EDIT: They should rotate together not individually
Do you have shoulder Motor6Ds on the character?
Yeah i do have a shoulder motor 6D
Alright, I’ll provide you with a script which works for R6 for the arm to follow your mouse, just change up the variables to make it work with your character. If you have any questions, just ask me.
Thanks in advance! I’ll see what i can do with it
Here you go.
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local leftShoulder = character:FindFirstChild("LeftShoulder", true) -- (Your character's left shoulder.)
local rightShoulder = character:FindFirstChild("RightShoulder", true) -- (Your character's right shoulder.)
local leftShoulderOriginCFrame = leftShoulder.C0
local rightShoulderOriginCFrame = rightShoulder.C0
local armMovement = movementValues:WaitForChild("ArmMovement") -- (The value which determines whether or not your arms are moving.)
game:GetService("RunService").RenderStepped:Connect(function()
if armMovement.Value then
if leftShoulder then
TweenService:Create(leftShoulder, TweenInfo.new(0.25), {C0 = leftShoulderOriginCFrame * CFrame.Angles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y), 0, 0)}):Play()
end
if rightShoulder then
TweenService:Create(rightShoulder, TweenInfo.new(0.25), {C0 = rightShoulderOriginCFrame * CFrame.Angles(-math.asin((mouse.Origin.p - mouse.Hit.p).unit.y), 0, 0)}):Play()
end
end
game.ReplicatedStorage.Events.MovementEvent:FireServer(neck.C0, leftShoulder.C0, rightShoulder.C0)
end)
armMovement:GetPropertyChangedSignal("Value"):Connect(function()
if not armMovement.Value then
if leftShoulder then
TweenService:Create(leftShoulder, TweenInfo.new(0.25), {C0 = leftShoulderOriginCFrame}):Play()
end
if rightShoulder then
TweenService:Create(rightShoulder, TweenInfo.new(0.25), {C0 = rightShoulderOriginCFrame}):Play()
end
end
end)
Thanks! I’ll try it out on my character
Oh, one thing, my character has only 1 arm (right arm) so a left arm isn’t needed but i think i can fix it by myself
I read the post and correct me if I’m wrong, but this seems like you’re overcomplicating it a lot. If this is something like a viewmodel needing to be attached to the camera, you can simply do this:
- make sure there is a root part in the viewmodel (ex: HumanoidRootPart)
- make sure the root part is anchored
- set the model’s PrimaryPart to the root part
- use this in a local script:
local run = game:GetService("RunService")
local cam = workspace.CurrentCamera
local Viewmodel = game.ReplicatedStorage.Viewmodel:Clone()
run.RenderStepped:Connect(function()
Viewmodel:PivotTo(cam.CFrame)
-- every frame, move the viewmodel onto the camera
end)
No, it’s actually a custom character, where the camera is facing the character so it looks like its 2D. My goal is to make the arm of the spider character point to the cursor.
Here’s a 2D demonstration i found on the internet (the square is supposed to be the arm)
For more clarification; I basically wanna make it so that you can rotate it just by moving your cursor, so basically this but without needing to drag the mouse.