So I am trying to do a drawbridge and it is kinda working at a certain position.
So I just want it to be rotated at a privot point 90 degree and it works like a charm if I rotate the bridge correctly.
But the problem is that the map I am building on is a little rotated, so my models arent like this:
They are like this :
This makes the drawbridge rotate weirdly as you can see in the gif : https://i.gyazo.com/466077479a5d9ed9b2c563005780c414.mp4
if the model is rotated correctly like the first picture then it’s going well :
https://i.gyazo.com/defdd7cc95d7d16b8d84fa5714abef7b.mp4
I was thinking on maybe adding another degree to counter this problem but I couldn’t find the solution yet.
game.ReplicatedStorage.DoorService.FireDoor.OnServerEvent:Connect(function(player,door,doorval)
local bridge = false
if door.Bridge.Value == true then
bridge = true
end
local pivot = door.Parent.SpinPart.Position
local part = door
local sound = door:FindFirstChild("Sound")
local newpivot = CFrame.new(pivot) -- Create decoy pivot that will "rotate"
local offset = newpivot:toObjectSpace(part.CFrame) -- Get the offset from the part to the pivot
local speed = 0
if bridge == true then
speed = 0.25
else
speed = 4
end
local function open()
sound:Play()
for i = 90/speed,0,-1 do
wait()
if bridge == false then
newpivot = newpivot * CFrame.Angles(0, math.rad(speed), 0) -- not a bride
else
newpivot = newpivot * CFrame.Angles(math.rad(-speed), 0, 0) -- a bride
end
part.CFrame = newpivot * offset
end
end
local function close()
sound:Play()
for i = 90/speed,0,-1 do
wait()
if bridge == false then
newpivot = newpivot * CFrame.Angles(0, math.rad(-speed), 0) -- Rotate the pivot
else
newpivot = newpivot * CFrame.Angles(math.rad(speed), 0, 0) -- Rotate the pivot
end
part.CFrame = newpivot * offset
end
end
--THIS PART IS NOT RELEVANT FOR THE PROBLEM
if debounce == false then
if doorval == true then
debounce = true
close()
door.State.Value = false
wait(1)
debounce = false
else
debounce = true
open()
door.State.Value = true
wait(1)
debounce = false
end
end
end)
Note: To explain the code a bit. It’s a Door/Gate remoteevent , that’s why I am checking at the beginning if bridge == true/false.
EDIT: Here is the model hierarchy
And here is the spinpart located