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

How to change CFrame rotation and position together?

Asked by
I_0KI 40
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

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. DropshipPilot 148 — 6y
Ad
Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
6 years ago

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)

Answer this question