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
Hello,
Can you tell me how to do it? Here are the things I want:
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?
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”
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.
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
RS.Heartbeat:Connect(function()
if Character and Character:FindFirstChild("Torso") and Activated 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)
And when you deactivate it should be something like this:
--Some event or anything
local RightShoulder = Character.Torso:WaitForChild("Right Shoulder")
RightShoulder.C0 = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, -0, -1, 0, 0)
This is how it looks like in a gun (When the gun goes up and down, I’m unable to do the other 2 Axis):
robloxapp-20210124-2318367.wmv (3.2 MB)
Hello,
I tested your script and it does not work.
wait(2)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
mouse.TargetFilter = workspace
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 lastmou
game:GetService("RunService").Heartbeat:Connect(function()
if char and char:FindFirstChild("Torso") then
local RightShoulder = char.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)
dude, hold yourself together man…
Anyways…
With regards to your script, your nearly there. Personally I take the approach of using angles instead of using pure cframes, this is because in your CFrame.new(point1, point2) solution you will very quickly run into issues when aiming directly up or down.
Anyways as for a solution I won’t give you any code but rather I will give you a few tips to how to get there.
A weld on an arm is offset, therefore you need to make sure to replicate that with this equation, I recommend using ToObjectSpace and ToWorldSpace.
For easier math you will want to localize the target based on the torsos CFrame.
As for the yaw and pitch of the arm, heres a great equation for that:
local yaw = math.atan2(-localizedTarget.X, -localizedTarget.Z)
local pitch = math.atan2(localizedTarget.Y, math.sqrt((localizedTarget.X ^ 2) + (localizedTarget.Z ^ 2)))
Now go learn some math!
As a side note, please don’t beg, your not going to get anywhere with that.
Hello,
Can you specify what you mean by ‘math’? Also, what is yaw and pitch, what does ToObjectSpace and ToWorldSpace do
Read up on this stuff.
When I refer to math I’m refering to the equations which are involved with CFrame operations, terms such as Radians, Rotational Matrix and Vector should be familiar to you.
Hello,
Is this what you are talking about when arm pointing upwards have issue?
wait(2)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
mouse.TargetFilter = workspace
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 lastmou
RunService.RenderStepped:Connect(function()
lastmou = mouse.Hit.p
local e = Instance.new("Part",workspace)
e.CFrame = CFrame.new(char.Torso.Position, mouse.Hit.Position)
e.Anchored = true
e.CanCollide = false
e.Size = Vector3.new(1,1,1)
game:GetService("Debris"):AddItem(e,.05)
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)
I have no idea how to fix it and if you could please help me that would be fine
Hello,
Also I would like it to so that the arm points inversely if your mouse is in the back of your character because human arms can’t move like that
Hello,
I did some math and it seems like I got it with UpVector and RightVector but for some reason setting the c0 of the armweld would make my arm float and it’s very weird because when I rotate my character and make it fall the arm just moves back and it stays there
wait(2)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
mouse.TargetFilter = workspace
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 lastmou
RunService.RenderStepped:Connect(function()
lastmou = mouse.Hit.p
local e = Instance.new("Part",workspace)
e.CFrame = CFrame.new(char.Torso.Position+char.Torso.CFrame.RightVector+char.Torso.CFrame.UpVector, mouse.Hit.Position)
e.Anchored = true
e.CanCollide = false
e.Size = Vector3.new(1,1,1)
game:GetService("Debris"):AddItem(e,.05)
local cframe = CFrame.new(char.Torso.Position+char.Torso.CFrame.RightVector+char.Torso.CFrame.UpVector, mouse.Hit.Position)
armWeld.C0 = cframe * CFrame.Angles(math.pi/2, 0, 0)
end)