Help with pointing arms

I am trying to point the arms to a specific point in the world, and that i want to do by modifying the motor6d’s in the rig.
I know that a motor6d works like this part0.CF*C0 is where the motor6d is. then part1.CF is offseted by C1.

so iv’e been making this script

local folder = script.Parent
local target = workspace.TT
--local Parts = {folder.Start, folder.Middle, folder.End}

local bias = (HumaoidRootPart.CFrame * CFrame.new(0,-10, 0)).Position
local targetPos = target.Position

local Bases = {cLeftShoulder, cLeftElbow, cLeftHand}
local Sizes = {UpperArmLenght, LowerArmLenght, 0}

--Bases[1] left shoulder motor6d
while true do
	deb.step()
	--deb.CFrame(Bases[1].Part0.CFrame * Bases[1].C0)
	local CF = Bases[1].Part0.CFrame * Bases[1].C0
	Bases[1].C1 = CFrame.new(Bases[1].C1.Position, CF:VectorToObjectSpace(target.Position))
	deb.CFrame(CF * Bases[1].C1)
	
	task.wait()
end

and the result is this:

is there something i’m missing?

Have you tried using CFrame.lookAt()?

you can get the angle that will make the arm look at a part by doing
local direction = Cframe.new(YourArmPosition,ThePartToLookAtPosition)
arm.CFrame = direction

it’s almost the same thing as
CFrame.new(vector3, vector3)
CFrame.LookAt let’s you add another vector3 that specifies the up vector

so those two are basically the same

1 Like

but that’s the arm cframe and not the motor6 CFrame

yeah i didnot read the forum well i will test in studio until i find a solution

That’s my bad, I forgot the CFrame constructor had multiple prototypes.
Just to make sure, what happens if you simply do Bases[1].C1 = CFrame.new(Vector3.zero, Bases[1].C0:VectorToObjectSpace(target.Position))?
It would be great to start off with the arm pointing in the right direction.

image

this happens

1 Like

Weird, can you do deb.CFrame(CFrame.new(Bases[1].C0:VectorToObjectSpace(target.Position)))? Assuming that is what renders those XYZ axes in the screenshots.

image
the magenta dot is the point you specified. it always stays on top of the target

deb.point(Bases[1].C0:VectorToObjectSpace(target.Position), Color3.new(1, 0, 1))
this is the line i added

here the link to the module

1 Like

i was tinkering a bit with the motor6D and i discovered this:

Motor6D.CFrame = Part0.CFrame * C0
Motor6D.CFrame = Part1.CFrame * C1

so part1.CF = Part0.cf * C0 * C1:Inverse()

I made an error where that debug point was basically useless because C0 was probably equal to a blank CFrame, so it was taking a vector in world space and converting it to the workspace’s local space (aka also world space, lol)
I find it weird that the shoulder is only rotating along the Y axis and not any other. I can’t think of anything else right now so I’d say just keep throwing things at it until something works.

Hello
The solution was as easy as a 12th grade mathematics problem


So we know as i’ve said in the last post that we have this equation
part1.CF * C1 = Part0.CF * C0
But keep in mind that the CFrame operations are not comutative; that means that CF1 * CF2 (CF1 ofsetted by CF2 amount) is not the same as CF2 * CF1 (CF2 offsetted by CF1 amount)

So the solution for C1 is the following
C1 = part1.CF:Inverse() * Part0.CF * C0

It means that you can now input any CFrame you want the arm in this case to part1.CF and you will have the motor6d C1 calculated for you


Proof! :slight_smile:

And Code

local deb = require(script.Debugger)


local folder = script.Parent
local target = workspace.TT
--local Parts = {folder.Start, folder.Middle, folder.End}

local bias = (HumaoidRootPart.CFrame * CFrame.new(0,-10, 0)).Position
local targetPos = target.Position

local Bases = {cLeftShoulder, cLeftElbow, cLeftHand}
local Sizes = {UpperArmLenght, LowerArmLenght, 0}

local pos = Bases[1].C1.Position
local mot = Bases[1]


while true do
	deb.step()
	--deb.CFrame(Bases[1].Part0.CFrame * Bases[1].C0)
	local WantedCF = CFrame.new((mot.Part0.CFrame * mot.C0).Position, target.Position) 
		* CFrame.Angles(math.pi/2,0, 0)
		* CFrame.new(0,-UpperArmLenght/2,0) 
	deb.point((mot.Part0.CFrame * mot.C0).Position, Color3.new(0.639216, 0, 0))
	deb.CFrame(WantedCF)
	local CF = Bases[1].Part0.CFrame * Bases[1].C0
	--Bases[1].C1 = CFrame.new(pos) * CFrame.new(Vector3.zero, Vector3.zAxis+ Vector3.yAxis)
	local point = (mot.Part1.CFrame:Inverse()):PointToObjectSpace(Vector3.zero)
	mot.C1 = WantedCF:Inverse() * mot.Part0.CFrame * mot.C0 

	
	task.wait()
end

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