# Rotating a Model Makes LookVector Weird

I’m writing a procedural generation system that places rooms.

Everytime a Player opens a door, a new room is made, connected to that door.

To place a room, it finds the room’s door with the opposite LookVector.
If there isn’t one, it’ll rotate the room until one of the doors has the opposite LookVector.

The function works just fine when it doesn’t need to rotate.

However, when it does the LookVectors for the doors become weird each time the model goes through a Rotation. Doing LookVector.Unit doesn’t round the numbers back to being 1, -1, or 0.

``````  22:00:22.062  Oppisite: 0, 0, -1 | Door -1, -0, 2.622683439312823e-07  -  Server - Dungeons:182
22:00:23.081  Oppisite: 0, 0, -1 | Door -3.059797393234476e-07, -0, -1  -  Server - Dungeons:182
22:00:23.081  Oppisite: 0, 0, -1 | Door 3.059797393234476e-07, -0, 1  -  Server - Dungeons:182
22:00:24.095  Oppisite: 0, 0, -1 | Door -1, -0, 3.4969113471561286e-07  -  Server - Dungeons:182
22:00:24.096  Oppisite: 0, 0, -1 | Door 1, -0, -3.4969113471561286e-07  -  Server - Dungeons:182
22:00:25.112  Oppisite: 0, 0, -1 | Door 3.9340253010777815e-07, -0, 1  -  Server - Dungeons:182
22:00:25.112  Oppisite: 0, 0, -1 | Door -3.9340253010777815e-07, -0, -1  -  Server - Dungeons:182
22:00:26.130  Oppisite: 0, 0, -1 | Door 1, -0, -4.3711392549994343e-07  -  Server - Dungeons:182
22:00:26.130  Oppisite: 0, 0, -1 | Door -1, -0, 4.3711392549994343e-07  -  Server - Dungeons:182
22:00:27.145  Oppisite: 0, 0, -1 | Door -4.808252924703993e-07, -0, -1  -  Server - Dungeons:182
22:00:27.145  Oppisite: 0, 0, -1 | Door 4.808252924703993e-07, -0, 1  -  Server - Dungeons:182
22:00:28.162  Oppisite: 0, 0, -1 | Door -1, -0, 5.245366878625646e-07  -  Server - Dungeons:182
22:00:28.163  Oppisite: 0, 0, -1 | Door 1, -0, -5.245366878625646e-07  -  Server - Dungeons:182
22:00:29.179  Oppisite: 0, 0, -1 | Door 5.682480832547299e-07, -0, 1  -  Server - Dungeons:182
22:00:29.180  Oppisite: 0, 0, -1 | Door -5.682480832547299e-07, -0, -1  -  Server - Dungeons:182
22:00:30.195  Oppisite: 0, 0, -1 | Door 1, -0, -6.119594786468951e-07  -  Server - Dungeons:182
22:00:30.195  Oppisite: 0, 0, -1 | Door -1, -0, 6.119594786468951e-07  -  Server - Dungeons:182
22:00:31.212  Oppisite: 0, 0, -1 | Door -6.556708740390604e-07, -0, -1  -  Server - Dungeons:182
22:00:31.213  Oppisite: 0, 0, -1 | Door 6.556708740390604e-07, -0, 1  -  Server - Dungeons:182
22:00:32.229  Oppisite: 0, 0, -1 | Door -1, -0, 6.993822694312257e-07  -  Server
22:00:32.229  Oppisite: 0, 0, -1 | Door 1, -0, -6.993822694312257e-07  -  Server
``````
``````local NewRoom, NewDoors = module.CreateRoom(Player, Dungeon)

local NewRoom: Model = NewRoom
local NextDoor: Part = nil

local MainLV = Door.CFrame.LookVector
local Opposite = MainLV * Vector3.new(-1,-1,-1)

for index, DoorTest:Part in pairs(NewDoors) do
if DoorTest.CFrame.LookVector == Opposite then
NextDoor = DoorTest
break
end
end

while not NextDoor do

local rotation = CFrame.Angles(0, math.rad(90), 0)
local modelCFrame = NewRoom:GetPivot()
NewRoom:PivotTo(modelCFrame * rotation)

for index, DoorTest:Part in pairs(NewDoors) do
print(`Oppisite: {Opposite.Unit} | Door {DoorTest.CFrame.LookVector.Unit}`)
local LV = DoorTest.CFrame.LookVector
if LV == Opposite then
NextDoor = DoorTest
break
end
end

print("DEBUG: Rotate!")
wait(1)
end
``````

Solved my own issue.

``````local NewRoomPos = NewRoom.PrimaryPart.Position
NewRoom:PivotTo(CFrame.new( NewRoomPos, NewRoomPos + Vector3.new(MainLV.Z,0,MainLV.X)))`````````

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.