How to make arm follow mouse

Hello,



What I have here is that it follows the mouse but here are two things i want to fix

  1. The arm to rotate relative to the shoulder instead of just the position of the arm
  2. The arm to rotate like the velocity of the mouse
    If the mouse goes diagonally left down, then the arm should orient right down



Like this insteaed of just going down without taking into account the velocity of the mouse hit

Also basically I want the arm to go the orientation ofthe look of the mouse which it goes around like a hollow sphere so when there are new objects it doesn’t just update like a very weirdly and stuff

So like a sphere and stuff and so it ignored the parts so it doesnt just go to the part because it appeared and stuff so basically just ignore everything for mouse hit is that possible can i do it pleas eplease please

- Br, iSyriux

6 Likes

CFrame.new(StartPos + Offset,Mouse.Hit.Position)*CFrame.new(0,0,-armlength)

1 Like

Hello,
Does not solve my problem with the arm orientation relative to the mouse velocity direction and the ignore everything mouse.hit thing did you even bother to read my entire post?

my apologies, for ignore every thing mouse u could use

local mouseRaycastParams = RaycastParams.new() --workspace

local function getMouseHit()
	local mousePos = userInputServ:GetMouseLocation()
	local unitRay = camera:ViewportPointToRay(mousePos.X, mousePos.Y)

	return workspace:Raycast(unitRay.Origin, unitRay.Direction * 250, mouseRaycastParams)
end

but for the velocity you could try using tween service

3 Likes

Hello,
What is the function supposed to return? How do I calculate a position from that?

Hello,
Here’s my script BTW.

local Players = game:GetService("Players")

local RunService = game:GetService("RunService")

local plr = Players.LocalPlayer

local char = plr.Character

local mouse = plr:GetMouse()

local armOffset = char.Torso.CFrame:Inverse() * char["Right Arm"].CFrame

local armWeld = Instance.new("Weld")

armWeld.Part0 = char.Torso

armWeld.Part1 = char["Right Arm"]

armWeld.Parent = char

local camera = game.Workspace.CurrentCamera

local mouseRaycastParams = RaycastParams.new() --workspace

local function getMouseHit(mousepos)

local unitRay = camera:ViewportPointToRay(mousepos.X, mousepos.Y)

return workspace:Raycast(unitRay.Origin, unitRay.Direction * 250, mouseRaycastParams)

end

RunService.RenderStepped:Connect(function()

local cframe = CFrame.new(char.Torso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0)

armWeld.C0 = armOffset * char.Torso.CFrame:toObjectSpace(cframe)

end)

It’s late and I don’t know what I’m doing. Explain to me how I can make this work?

I would take a different approach. Instead, return the vector from the mouses hit to camera and the look vector of the arm. From there find the delta difference of the arm to the camera vector and interpolate that delta difference with quaternions so no arm breaking. See ego mooses thingie on advanced cframe tricks (aligning 2 vectors)

Maybe try using a method where you change the attachment point for the motor6D connecting the arm to the torso?

Hello,
Can you tell me how to do it? Here are the things I want:

  • Arm rotates relative to the shoulder joint
  • Arm orientation as mouse velocity
  • Ignore all objects when detecting mouse hit so it doesn’t suddenly do stuff

If you want to rotate it around a joint just update the c0 of that joint instead. If you want it to not be instant simply interpolate it. And for the ignore all objects simply apply a mouse filter

Hello,
How do I update the c0 of that joint? I have no clue

Hello,
Also, what is this weird behaviour right here?


It’s not rotating like a normal human arm would

Hello,
I Basically want this

Hello,
This is my other post explaining further in depth how this works BTW.

Thought you guys should check it out to be able to help me more, pretty stuck right now.TheInfo I’ve gathered since this post is that it should actually go around in a sphere formation, an infinite amount of circle paths in every orientation basically, yeah, based on the movement of the mouse in the workspace allthewhile ignoring everything in workspace so there are no sudden moves. Gotchya.

If you want the joint to move around a fixed point you do this cool cframe trick where we multiply it by itself, see this ROBLOX: Rotating an object relative to a fixed point with CFrame (Door animation) - YouTube

Hello,
I watched through the entire 17 minute video And found no useful tips on how to apply this to a script, let alone my script which rotates the arm of a character, which needs the motor6d to be retained if the script is turned off.

After I heard your cries of help, I will try to show you my mediocre script.

RS.Heartbeat:Connect(function()
	if Character and Character:FindFirstChild(Tool.Name) and Character:FindFirstChild("Torso") then
		local RightShoulder,= Character.Torso:WaitForChild("Right Shoulder")
		local X = -(math.asin((Mouse.Origin.p - Mouse.Hit.p).unit.y))
		local _, Y, Z = RightShoulder.C0:ToEulerAnglesXYZ()
		RightShoulder.C0 = CFrame.new(RightShoulder.C0.Position) * CFrame.Angles(X, Y, Z)
	end
end)

RS = RunService, Character = the players character and Mouse is the Player:GetMouse()

Also this only works up and down, in R6 only. I belive you must find another Joint rather than “Right Shoulder”

4 Likes

Hello,
I tested out your script and it does not work.
The arm disappears

Are you sure you are using R6 and an Tool? I forgot that the Tool variable should be the Tool the players needs to be equiped so the arm will follow the mouse. Deleting and Character:FindFirstChild(Tool.Name) will make it so no Tool is needed.

1 Like

Hello,
I don’t want to use a tool for it yet, I just want it to work whenever for now before I empliment any activationl ogic. One thing to keep out on is that I want it to be togglable so when it turns off the arm returns back to normal and doesn’t break or stay in the same place