Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 01 Jul 2016 07:48 PM |
the player's mouse?
I have a script in which the player's arms are welded to the torso and use the shoulder joints to follow the player's mouse vertically. I need to do this in unison with ROBLOX animations, which use the shoulder joints, so I need to get it working with the neck joint. How do I do this?
local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local character = player.Character or player.CharacterAdded:wait() local torso = character:WaitForChild("Torso") local arm1 = character:WaitForChild("Left Arm") local arm2 = character:WaitForChild("Right Arm") local lShoulder = torso:WaitForChild("Left Shoulder") local rShoulder = torso:WaitForChild("Right Shoulder")
weld1 = Instance.new("Weld", torso) weld1.C0 = CFrame.new(-1.5,.5,0) weld1.Part1 = arm1
weld2 = Instance.new("Weld", torso) weld2.C0 = CFrame.new(1.5,.5,0) weld2.Part1 = arm2
local offset = CFrame.new(0,0,-0.5)*CFrame.Angles(math.pi/2,0,0) local yz = Vector3.new(0,1,1) local function FPS_Arms() arm1.LocalTransparencyModifier = 0 arm2.LocalTransparencyModifier = 0 local tCFrame, hit = torso:GetRenderCFrame(), mouse.Hit.p local p0c0 = tCFrame*weld1.C0 weld1.C1 = (CFrame.new(p0c0.p, p0c0*(p0c0:inverse()*hit*yz))*offset):inverse()*p0c0 local p0c0 = tCFrame*weld2.C0 weld2.C1 = (CFrame.new(p0c0.p, p0c0*(p0c0:inverse()*hit*yz))*offset):inverse()*p0c0 end
local function CameraModeChanged(prop) if prop ~= "CameraMode" then return end if player.CameraMode == Enum.CameraMode.LockFirstPerson then game:GetService("RunService"):BindToRenderStep("FPS_Arms", Enum.RenderPriority.First.Value, FPS_Arms) lShoulder.Part0 = nil rShoulder.Part0 = nil weld1.Part0 = torso weld2.Part0 = torso else game:GetService("RunService"):UnbindFromRenderStep("FPS_Arms") lShoulder.Part0 = torso rShoulder.Part0 = torso weld1.Part0 = nil weld2.Part0 = nil end end
player.Changed:connect(CameraModeChanged) CameraModeChanged("CameraMode")
|
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
| |
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
| |
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
| |
|
|
| 01 Jul 2016 09:42 PM |
What? Are you saying you need to be able to move the arms to generally follow the mouse, but also need to control them via animations?
If so, you need to modify the C0 of the shoulders. Don't weld anything to anything else, just use the existing shoulder joints. Animations use the C1 of the joints, so it won't affect anything.
|
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 01 Jul 2016 09:47 PM |
How can I modify the script to do that?
|
|
|
| Report Abuse |
|
|
|
| 01 Jul 2016 10:41 PM |
Well, most of it is extra now. Some of the CFrame math could be useful, but I imagine a lot of it is going to have to be modified too, especially considering you don't want it to actually face the mouse.
You essentially have to rewrite the whole script, there's not a whole lot of similarities. Why don't you start by detailing EXACTLY what you want the script to do?
|
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 01 Jul 2016 11:46 PM |
I want the player's arms to move vertically (just up and down) so that they follow the mouse's movements while the player is in first person mode without overriding roblox animations
|
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 12:52 AM |
Something like this? Intended for a localscript in StarterPlayerScripts
local player = game.Players.LocalPlayer; repeat wait() until player.Character; local character = player.Character; local mouse = player:GetMouse();
local root = character:WaitForChild("HumanoidRootPart"); local torso = character:WaitForChild("Torso");
local leftShoulder = torso:FindFirstChild("Left Shoulder"); local rightShoulder = torso:FindFirstChild("Right Shoulder");
local function MoveArms() if (not mouse.hit) then return; end local angle = math.asin((mouse.hit.p-(root.Position+Vector3.new(0, 0.5, 0))).unit.y); if leftShoulder then leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0) * CFrame.Angles(0, 0, -angle); end if rightShoulder then rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0) * CFrame.Angles(0, 0, angle); end end
game:GetService("RunService"):BindToRenderStep("Move Arms", Enum.RenderPriority.Last.Value, MoveArms);
|
|
|
| Report Abuse |
|
|
Widths
|
  |
| Joined: 12 Aug 2014 |
| Total Posts: 41286 |
|
|
| 02 Jul 2016 01:22 AM |
Works perfect, thank you! The only issue being that if you walk up to a wall, your arms fly upward. Is there any way to fix that?
|
|
|
| Report Abuse |
|
|
|
| 02 Jul 2016 09:04 AM |
local angle = math.asin((mouse.hit.p-(root.Position+Vector3.new(0, 0.5, 0))).unit.y);
change to
local angle = math.asin((mouse.hit.p-(root.Position+Vector3.new(0, 1.5, 0))).unit.y);
maybe?
|
|
|
| Report Abuse |
|
|