Rotational Problem with CFrame

Hey developers,

I’m currently writing a function that essentially shakes a model. I’ve run into an issue while rotating the parts: sometimes the orientation changes drastically compared to the small angle it should be changing. Particularly, I’ve noticed this happening when the part’s orientation ~= 0


Here’s my code:
tween1 changes the part’s CFrame while tween2 returns it to its original CFrame

It should only be rotating the part by r degrees, but often (if the part’s orientation is not 0) it will rotate what appears to be anywhere from 90 to 270 + r.

1 Like

I am not that good with this stuff. But I will try to help ya’ the most that I can. I may be missing something, but perhaps the model is already rotated, lets say it is rotated at 270 degrees, then the code trys to bring the model to 15 degrees, which is a lot compared to when the model starts at 0 degrees. Perhaps you can try to print _r and see what the value is. Also, it may look like the tween is changing too fast and you may need to define the speed to play it at. Like I said, I am not that good with this type of stuff, but I will try to provide as much help as I can.

As @PiAndInfinite has already explained. You aren’t taking into account the current rotation of the part.
The way you can take into account its rotation is by doing the following…

CFame = v.CFrame * CFrame.new(0,h,0) * CFrame.Angles(0,math.rad(r),0)
2 Likes

Thanks a million guys! I thought I had been taking it into account; thanks for the notational help @Xx1Luffy1xX.