How To Point R6 Arm To Mouse?

I know very basic about CFrames perhaps even less.

I would like to know if its possible to enable limits too so players arm does not go behind them.

Here is my current code

Torso["Right Shoulder"].C0 = CFrame.lookAt(Character.Torso["Right Shoulder"].C0.Position, Mouse.Hit.Position)

Here is how it reacts
image

I’ve checked other forums and nothing has helped. Would appreciate explanation.

1 Like

please check harder next time:

you need to make sure that you just ajust the cframe every frame by using runservice

1 Like

You should actually study CFrames before making a post like this. It’s really not necessary to make a post just to have it explained. You should refer to the API, or review the many free tutorials on youtube about CFrames to learn. They’re not hard.

Not body Arms only, I tried reconstructing them to my situation nothing helped.

I tried studying them since morning I watched youtube and everything none of them have helped muched, I even went back to learning math. The API is bs can barely understand what they mean and what some constructors do.

You don’t need math to understand CFrames. All the math is done for you interally already. You just need to understand the result of the methods.

Are you sure that applies for every type of situation?

Most of the time meddling with CFrames are easy. It’s usually just order of operations and basic arithmetic. For example, if I wanted to rotate a cframe around a point, I would use this operation:

rotatedCFrame = point * rotation * oldCFrame

There’s rarely a time where you need to use CFrame:GetComponents() to get all the internal values of the CFrame.

How would I write where to point a object orientation at to find a certain position?

Something with lookAt?

You could use this

CFrame.new(position1, position2)

it will create a CFrame at position1, looking at position2, where both are *Vector3*s.

1 Like

This what I cooked but it does nothing when I play it. What am I doing wrong?

C0 = CFrame.new(C0.Position, MousePos)

C0 is an offset for joints, you have to say:

joint.C0 = yourCFrame
1 Like

Full code, still nothing

RunService.Stepped:Connect(function()
	local C0, MousePos = Torso["Right Shoulder"].C0, Mouse.Hit.Position
	C0 = CFrame.new(C0.Position, MousePos)
end)

This is how its going so far,

image

It is following the cursor but I’m trying to get the correct face to point at the mouse which is the palm currently you can see that it is the front of the arm is facing the mouse position.

Code:

local function worldCFrameToC0ObjectSpace(motor6DJoint,worldCFrame)
	local part1CF = motor6DJoint.Part1.CFrame
	local c1Store = motor6DJoint.C1
	local c0Store = motor6DJoint.C0
	local relativeToPart1 =c0Store*c1Store:Inverse()*part1CF:Inverse()*worldCFrame*c1Store
	relativeToPart1 -= relativeToPart1.Position

	local goalC0CFrame = relativeToPart1+c0Store.Position--New orientation but keep old C0 joint position
	return goalC0CFrame
end


RunService.Stepped:Connect(function()
	local goalCF = CFrame.lookAt(RightArm.Position, Mouse.Hit.Position, -Torso.CFrame.UpVector)
	Torso["Right Shoulder"].C0 = worldCFrameToC0ObjectSpace(Torso["Right Shoulder"],goalCF)
end)

Here is the code guys, I’ll explain what is happening.

The front of the arm looks at the position of the players mouse after that we adjust it by 80 degrees which results in the palm facing the mouse, sounds simple but this took 2 days.

Code:

local function Point_C0_To_Mouse(Motor6D, WorldCFrame)
	local Part1_CFrame = Motor6D.Part1.CFrame
	local Stored_C1 = Motor6D.C1
	local Stored_C0 = Motor6D.C0
	local RelativeTo_Part1 = Stored_C0 * Stored_C1:Inverse() * Part1_CFrame:Inverse() * WorldCFrame * Stored_C1
	RelativeTo_Part1 -= RelativeTo_Part1.Position

	local Goal_C0 = RelativeTo_Part1 + Stored_C0.Position
	return Goal_C0
end


RunService.Stepped:Connect(function()
	local Mouse_Pos = Mouse.Hit.Position
	RightShoulder.C0 = Point_C0_To_Mouse(RightShoulder, CFrame.lookAt(RightArm.Position, Mouse_Pos)) * CFrame.Angles(0,0, math.deg(-90))
	LeftShoulder.C0 = Point_C0_To_Mouse(LeftShoulder, CFrame.lookAt(LeftArm.Position, Mouse_Pos)) * CFrame.Angles(0,0, math.deg(90))
end)
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.