Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I point a Characters Arm to the Mouse?

Asked by 9 years ago

How would I point a Characters Arm to the Mouse?

I've posted this question multiple times with no good answers. Can someone like Bluetaslem answer this with detailed knowledge making it was easier to understand. I'm not trying to be a jerk, but i need some really good information to understand.

I'm using "Weld" to weld the arms instead of Motor 6d

2 answers

Log in to vote
1
Answered by 9 years ago

Based on what adark said, I created a short, little demonstrative LocalScript (not FilteringEnabled compatible).

while not game.Players.LocalPlayer.Character do
    wait(0.1)
end

wait()

local arm = game.Players.LocalPlayer.Character["Right Arm"]
local shoulder = game.Players.LocalPlayer.Character.Torso["Right Shoulder"]

local C0 = CFrame.new(arm.Position - shoulder.Parent.Position)

local weld = Instance.new("Weld", shoulder.Parent)
weld.Part0 = weld.Parent
weld.Part1 = arm
weld.C0 = C0

shoulder:Destroy()

while wait(0) do
    local direction = (CFrame.new(C0.p, game.Players.LocalPlayer:GetMouse().Hit.p) * CFrame.Angles(math.rad(90), 0, 0) + Vector3.new(0, 0.6, 0))

    weld.C0 = direction
end

This gets the general idea going. I had to create my own Motor6D -> weld system, since I didn't really know what kind of an environment you're working in. It should also be noted that my script quality and efficiency is not what it normally is, I threw this together in a hurry to be an example, not fully functional script. You can try it for yourself; put the script in StarterGui or StarterPack and watch what happens.

Ad
Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Since Welds use CFrames directly, I'll give you this tip to start with:

CFrame.new(Arm.Position, Mouse.Hit.p) -- Creates a CFrame at `Arm.Position`, pointing at `Mouse.Hit.p`
-- This is, effectively, setting the lookVector of a CFrame.

This, however, will cause the arm to be sideways, since we want to aim the bottom face of the Arm, not the Front face as that code alone will do. To fix this, we simply rotate it:

CFrame.new(Arm.Position, Mouse.Hit.p)*CFrame.Angles(math.rad(90), 0, 0)

Answer this question