So I’ve been trying to do this for about two days now.
My goal is to take these two doorways, I’ll call them DoorA and DoorB, then take a room and rotate it and position it in the proper direction and location relating to its forward vector and general location. (Please note they have to work with off grid placements and odd rotations)
With that said all the math has to be done in terms of the doors themselves rather than world space.
Its also built to be modular so using DoorA or DoorB as the first figure can’t be forced.
Here is what I have so far.
local changeVector = (doors[b].CFrame:ToObjectSpace(workspace.Part:GetPivot()).Position)
local rotVector = (doors[b].CFrame:ToObjectSpace(workspace.Part:GetPivot()).Rotation)
local rX, rY, rZ = rotVector:ToEulerAngles()
local rX = doors[a].CFrame.RightVector * rX
local rY = doors[a].CFrame.UpVector * rY
local rZ = doors[a].CFrame.LookVector * rZ
local x = doors[a].CFrame.RightVector * -changeVector.X
local y = doors[a].CFrame.UpVector * changeVector.Y
local z = doors[a].CFrame.LookVector * changeVector.Z
local transform = x + y + z
local rotation = rX + rY + rZ
local rotation = CFrame.Angles(rotation.X - doors[a].CFrame.Rotation.X, rotation.Y
- doors[a].CFrame.Rotation.Y, rotation.Z - doors[a].CFrame.Rotation.Z)
--dupes[v][v2]:PivotTo(CFrame.new(doors[a].CFrame.Position + compare.Position ))
dupes[v][v2]:PivotTo(CFrame.new(transform + doors[a].CFrame.Position) * rotation)
dupes[v][v2].Highlight.OutlineColor = doors[a].ConeHandleAdornment.Color3
And now you can see their reaction and what I want to happen.
Its a no brainer that isnt supposed to react that way. I’ve tried switching the rotations around setting them to negitives, so on and so fourth, but I really cannot solve this issue.
Here is one example of the current issue and desired position.
The Red one in this case lines up perfectly fine. The blue one is backwards. You can see the desired one lining up with all the others, while the actual one is essentially rotated 180 degrees.
I’ve tried and tried again for about 16 hours, decided it is worth coming here for.
1 Like
Could you elaborate more on the goal or how the doorways and rooms should look?
1 Like
Look at the image I sent. The red part relates the the red arrow. The arrows point away from the original part (To show where the generation is happening and is used for other code.)
What I need is the new highlighted parts to be located in terms of both doors. So you can see the top of the ORIGINAL “L” shaped platform is on the red arrow, So the blue L shaped platform should have the exact same comparison.
It sould have the top of the Blue L positioned at the arrow, but instead its rotated 180 about the Y.
Both x and Z are god awful but lets start with solving Y first.
1 Like
Well, for me I only use CFrames for orientation. I can collect the position part of a CFrame, and multiply a CFrame.Angles() to change rotation.
Unless there is a very specific reason you have to use position in the CFrame, you might find it easier to change the position property itself and then use CFrame for just the rotation.
Changing the position itself updates the CFrame anyways I believe.
1 Like
I have to have the position changed in terms of the doors. So I need to have it move in the object space rather than world space, hence CFrames.
1 Like
From looking at the video, the orientation of the blue door affects the orientation of the red highlighted part. But I’m assuming from your explanation that each door should only be moving their designated part, correct?
1 Like
Yea because they have to move in terms of one another. So if they are flat, they wont have any rotational offset. But of one door has a Y of 0 and the other a Y 0f 90, the roation of the room should follow that orientated offset.
Desired Effect–
Could you explain the process of the math in your script or add comments to it? There’s a lot of variables being overidden, so I’m struggling with trying to comprehend it. It looks like your mixing the components of doorA and doorB throughout your math, which shouldn’t be necessary if they’re supposed to be acting independently of each other.
local changeVector = (doors[b].CFrame:ToObjectSpace(workspace.Part:GetPivot()).Position)
local rotVector = (doors[b].CFrame:ToObjectSpace(workspace.Part:GetPivot()).Rotation)
-- changeVecor and rotVector are the offset and rotation offset of one door to the Copy Object.
local rX, rY, rZ = rotVector:ToEulerAngles()
-- These are just the rotational Vector in single values
local rX = doors[a].CFrame.RightVector * rX
local rY = doors[a].CFrame.UpVector * rY
local rZ = doors[a].CFrame.LookVector * rZ
-- I take those rotational values and apply them to what I think is the doors positive vectors
local x = doors[a].CFrame.RightVector * -changeVector.X
local y = doors[a].CFrame.UpVector * changeVector.Y
local z = doors[a].CFrame.LookVector * changeVector.Z
-- These are the position vector being applied to the doors positive vectors as well.
local transform = x + y + z
local rotation = rX + rY + rZ
-- Then they all get added together in two neat vectors.
local rotation = CFrame.Angles(rotation.X - doors[a].CFrame.Rotation.X, rotation.Y
- doors[a].CFrame.Rotation.Y, rotation.Z - doors[a].CFrame.Rotation.Z)
-- Create a Cframe from the Rotations
--dupes[v][v2]:PivotTo(CFrame.new(doors[a].CFrame.Position + compare.Position ))
dupes[v][v2]:PivotTo(CFrame.new(transform + doors[a].CFrame.Position) * rotation)
dupes[v][v2].Highlight.OutlineColor = doors[a].ConeHandleAdornment.Color3
So is this math only for doorA?
Its Looped through any door that exists and finds its respective pair.
I’m only seeing one PivotTo function, so does each door in a pair use the exact same math?
I’m not seeing too much wrong with the math, so maybe the issue lies in how it’s being applied.
Oh likely the case. I just made a test function to make sure it properly flips objects and its got some weird bugs as well.
local PlayerVel = Character.HumanoidRootPart.AssemblyLinearVelocity
-------------
local lookV = CurrentZone.CFrame.LookVector
local DesiredVel = lookV / Vector3.new(math.abs(lookV.X), math.abs(lookV.Y), math.abs(lookV.Z))
local PlayerVel = PlayerVel / Vector3.new(math.abs(PlayerVel.X), math.abs(PlayerVel.Y), math.abs(PlayerVel.Z))
local mathed = DesiredVel - PlayerVel
local x, y ,z = mathed.X, mathed.Y, mathed.Z
if math.abs(x) ~= 2 and math.abs(y) ~= 2 and math.abs(z) ~= 2 then
-- If Player is moving in an acceptable direction the pass
local zonePair = Zones[CurrentZone.Name]
local a = table.find(zonePair, CurrentZone)
local b = if a == 1 then 2 else 1
-- a is the interacted Zone
-- Temporary Door Flip for Math
local flippedDoor = CFrame.new(zonePair[b].CFrame.Position) * zonePair[b].CFrame:Inverse().Rotation
local charOffset = zonePair[a].CFrame:ToObjectSpace(Character:GetPivot()) -- Compared to zone A
local camOffset = zonePair[a].CFrame:ToObjectSpace(workspace.CurrentCamera.CFrame) -- Compared to zone A
print(charOffset.Position)
--local change = Zones[CurrentZone.Name][1].Position - Zones[CurrentZone.Name][2].Position
Character:PivotTo(flippedDoor:ToWorldSpace(charOffset))
workspace.CurrentCamera.CFrame = (flippedDoor:ToWorldSpace(camOffset))
end
Im in great pain.
So I found out what caused this. So I made it so it would flip the door since I need it to act as if its pointing in the opposing direction, so I used Angles:Inverse()
. Problem is, if you use that, inverse of 180 is the rame rotation.
How would I flip a door across its aiming vector? So if its rotated at Vector(0, 90, 0)
I would need Vector(0, -90, 0)
in return. Inverse doesnt work, and neither does just subtracting 180 from all of them.
Can’t this be done by manipulating its CFrame?
Well yea. Thats what I was trying to do…
I THINK I DID IT THO!
local flippedDoor = CFrame.lookAt(zonePair[b].CFrame.Position, (zonePair[b].CFrame.Position + -zonePair[b].CFrame.LookVector))
I instead of trying to rotate the Cframe I applied the negitive of its lookVector and just use Cframe.lookAt. (: