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

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

Asked by 6 years ago

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)
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) MedievalBeast4 4 — 6y
0
BodyGyro probably wouldn't work out, but thanks for the tip. Might help in the future. Jesse1240 59 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

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!

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. Jesse1240 59 — 6y
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? Jesse1240 59 — 6y
0
That's a whole different issue, which I don''t have enough info to solve. hiimgoodpack 2009 — 6y
Ad

Answer this question