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

How do I CFrame this so a part points toward a certain orientation?

I have two parts that are welded together. One is named PivotPart, and the other is named Flag. The flag pivots around the PivotPart, and it's told to point towards a certain orientation. So how do I make the flag point towards whatever WindDegree is by "CFraming from the weld"?

I'm terrible with CFrames, absolutely terrible. I don't understand them that well and all explanations that I can possibly find are confusing. I understand that they are positions and rotations, and the fact that they use matrices. I can't find anything to help me with this.

What I've tried:

ship = script.Parent
WindDegree = 45
ship.PivotPart.Weld.C0 = ship.PivotPart.Weld.C1 * CFrame.fromEulerAnglesYXZ(0,WindDegree,0)

2 comments

0

I'm not quite sure how to fix your problem - persay - however, you could try using a BodyGyro. And for future reference, you can angle a vector3 towards another vector3 via this line of code: CFrame.new(vectorFrom, vectorTo)

0

BodyGyro probably wouldn't work out, but thanks for the tip. Might help in the future.

1 answer

✓ Accepted answer

This is because CFrame needs RADIANS. To convert 45 degrees to radians, we can do

math.pi / 4

or

math.rad(45)

or

45 * 0.0174533 --stole off google

To fix this, your code would be

local ship = script.Parent --local variables are quicker to access
local WindDegree = math.rad(45)
ship.PivotPart.Weld.C0 = ship.PivotPart.Weld.C1 * CFrame.fromEulerAnglesYXZ(0,WindDegree,0)

Hope this helps!

3 comments

0

Thanks, somewhat got it fixed. It at least points towards whatever degree it is. For some reason the flag is way off in the distance though, and not at the FlagPivot's position.

0

Do you know how I could make it pivot around the FlagPivot? It turns correctly but the Flag is way off in the distance. How would I set the position and the rotation together?

0

That's a whole different issue, which I don''t have enough info to solve.

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