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

How do you update the angle and position of a model in a CFrame?

Asked by 7 years ago

So here's my idea: I want to make an platform (a model) that can go up and down by itself, and rotate, However, i have no clue how to do it.

So far, here's what I know:

Model:SetPrimaryPartCFrame(CFrame.new(x,y,z))

Moves the model to that position,

Model:SetPrimaryPartCFrame(CFrame.Angles(rotation x, rotation y, rotation z))

Rotates the model accordingly. Combine them together,

Model:SetPrimaryPartCFrame(CFrame.new(x,y,z))
Model:SetPrimaryPartCFrame(CFrame.Angles(0, 0, math.rad(dn)))

And it only updates the angle of my model.

Any help would be appreciated.

  • RealCMDMinecraft

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Remember...

Don't forget that CFrame represents a position and a rotation matrix. The CFrame.new constructor with only it's position field given (the first 3 arguments), yields no rotation. Likewise, the CFrame.Angles constructor rotates a CFrame, but has no given position field (so it defaults to 0,0,0).


In very few instances do you only care about rotation, and not position as well. Otherwise, you're rotating in relation to... what? The purpose of CFrame.Angles is most effectively used as an operand for an existing CFrame. This way, you can maintain position while setting (or modifying) rotation. The solution? Multiplying them together.

Model:SetPrimaryPartCFrame(CFrame.new(x,y,z) * CFrame.Angles(x,y,z))

Hope this helped, let me know if you have any questions.

Ad

Answer this question