CFrame.Angle(0, math.rad(180), 0) causing misrotation sometimes

I don’t understand why in like 1/100th of the time my dungeon have problem with the orientation my reasoning is I think it has to do with CFrame.Angle(0, math.rad(180), 0) mispreading the remaining angles and instead not keeping all of the 180 degree on the Y Axis does somebody already had this problem before if so how did you solve it ? Like sometimes it spreads (-90, 90, 0) like this sometimes it’s (90, 90, 0) etc.

8 Likes

Like instead it should do this

6 Likes

Try not going all the way to 180; 179 should work fine. Steps of 90 also work well. There is a number conversion at the quarter marks when a number can flip from positive to negative, which can sometimes throw off the rotation calculation.

You’re saying 180, it’s taken it as -180 … it can’t misread 179 that way.
Splitting that into 3 steps of the full rotation will work also. ← I use this

The other way is to just add 1 degree to rotate it, checking if it’s where you want to change direction, then subtracting 1 degree until it’s back to the start.

Edit: AND there is CFrame.fromEulerAnglesXYZ() that I included in the post with the download.

7 Likes

Oh thanks I’ll try what if I try like 179.9 will it round ?

5 Likes

Ok now my dungeon piece are bending yayt

5 Likes

You can see when this will happen with a simple test: Go to the part you wish to move and manually type in 180. If that number changes to -180 you’re going to have this problem. It’s all about where it happens to be …

4 Likes

I am trying -180 and seems to work pretty fine now

3 Likes

Sweet, just keep this in mind when doing this and you will have no more problems.

3 Likes

Nope still have problems yayt oh man I thought -180 would solve it. Why is it spreading the 90 degree on some axis

3 Likes

I think the rotation problem of 90 degree that spreads has to do with the door being chosen on the dungeon dependant on the corridor I don’t know how to explain it

4 Likes

Can we see your script for this …

4 Likes

Humm not sure if I want other people to have the script of my dungeon I don’t want to create other competitors though can only give you the most important parts but not all the dungeon script. I worked hard on making the dungeon system so

3 Likes

Just the door script … would be fine.

3 Likes

Oh alright man I can give you that

3 Likes

local offset = (lastPieceDoor.CFrame * CFrame.Angles(0, math.rad(-181 + 1), 0)) * nextPieceDoor.CFrame:Inverse() * offsetCFrame
nextPiece:PivotTo(offset * nextPiece:GetPivot())

3 Likes

And this is being activated from a touch? (on the door)

3 Likes

First room generated

newPiece.Parent = game.Workspace.GameDungeon:FindFirstChild("Stage" .. NUMBER_STAGE)
newPiece:PivotTo(CFrame.new(startingPosition) * CFrame.Angles(0, math.rad(PossibleAngles[AngleIndex]), 0))```
2 Likes

Basically the system decide to choose the door from the previous room and snap the piece into this specific door

2 Likes

So A door could end up at any angle?

2 Likes

Exactly because the piece can be rotated at any angle from -180 to 90 for now seems like the little simple math addition seems to work well on replacing the piece to -180 degree which is then convert to 180 degree in positive I’ll keep testing to see if there isn’t some issues

2 Likes