Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change CFrame rotation and position together?

I am currently making a localscript that animates a player with welds, and I need to animate the left arm's angle while moving its position as well, but I have no idea how to do that. Here's what I have so far.

wait(1)
lpchar = game.Players.LocalPlayer.Character
leftarm = lpchar["Left Arm"]
torso = lpchar["Torso"]
leftarmweld = Instance.new("Weld", leftarm)

leftarmweld.Part0 = torso
leftarmweld.Part1 = leftarm
leftarmweld.C0 = CFrame.Angles(0,0,-1)
leftarmweld.C0 = CFrame.new(-1.5,0,0) --This one cancels the above line out.

2 answers

✓ Accepted answer

Check out the CFrame page on the wiki while/after reading this answer: http://wiki.roblox.com/index.php?title=CFrame

CFrames are tricky. If you're trying to put a CFrame with a CFrame, you HAVE to multiply; this is the case when doing CFrame.Angles. (You can still add or subtract a Vector3 to/from CFrames without incident.)

so the way I would go about doing this, in steps, is

  • take the original position of the arm
  • either: A. State a new cframe with "leftarmweld.C0 = CFrame.new(yourX,yourY, yourZ)" B. Start with the original arm position and add a vector3 to offset it. "C0 = C0 +Vector3.new(x,y,z)"

then

  • Multiply that by the CFrame.Angles you want.

Here's an example. This code takes the arm, and moves it one stud above where it already is, turning it to face up 90 degrees. it'll probably look ridiculous, but whatever! So long as it works!

leftarmweld.C0 = leftarmweld.C0 * CFrame.Angles(math.rad(90), 0, 0) + Vecor3.new(0, 1, 0)

let me know if there's any problems and i'll make a comment correcting any mistakes

1 comment

0

Also! I have to warn against using Localscripts. Try doing this with a normal Script instead, for now, since FilteringEnabled keeps localscripts from changing objects usually.

Wouldn't it be like this?:

local X = --The variable name says everything
local Y = --The variable name says everything
local Z = --The variable name says everything
leftarmweld.Position = Vector3.new (X, Y, Z)

This discussion is preserved as it was. New answers, comments, and votes are closed.