Very weird problem regarding position

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
image
And here is the spinpart located

I had that problem until I created a Primary Part that became the alignment for my rotation. I could then rotate the model to whatever angle I wanted before moving stuff in relation to the angle. Sometimes I’ll stuff everything inside a big root part that is like the frame work that everything else is attached to. I make it invisible and no collisions but then I have 1 single block which is fundamentally the chassis that the rest is built into.

Once I get my alignment spot on, then the stuff inside can do what ever it wants.

To me, it looks like you have an object that the rotation is aligned to, which is messing up your rotation axis.

Strange though because they seem to be all aligned well.

My issue came from like making my own warped trees with many objects making up clumps of leaves.

Maybe try putting the Door inside the SpinPart, and making the SpinPart the primary part.

That way the spin is aligned. Then inside that microworld, the Door reacts with it’s own axis.

Or, put the Spinpart and the Door inside a BridgeRootPart, and make the BridgeRootPart the primary part, and have it aligned.

2 Likes

Sadly this didnt change anything hmm

Ok so what I see here is you have a CFrame made from SpinPart Position. Meaning no angles.

newpivot is basically a position with a 0,0,0 orientation.

After that, you are multiplying it by the angles 0, speed, 0

If you change the newpivot to the CFrame instead of the Position, is should have the orientation added too. Then

newpivot = newpivot * CFrame.Angles(0, math.rad(-speed), 0)

should be like
CFrame.New(vector3(23, 18, 9),vector3(17,5,12) * CFrame.New(vector3(0, 0, 0),vector3(0,math.rad(-speed),0)
instead of
CFrame.New(vector3(23, 18, 9),vector3(0,0,0) * CFrame.New(vector3(0, 0, 0),vector3(0,math.rad(-speed),0)

I know the rads aren’t in the vector3 thing but that’s not my point. My point is there are no existing angles of the part because you are only using position. You are basically using the orientation of the baseplate.

I’m not sure if this is the way it works since I’m not good with angles. So I’m not too familiar with your code and how it works.

You shouldn’t be setting CFrames to animate a drawbridge, it won’t move smoothly (once you publish the game) and it will interact with players on top of it in a glitchy way, with potential to fling them. If you use a HingeConstraint, you have total control over the axis of rotation because you can rotate the Attachments independent of the Part/Model.

1 Like

I’ve tested it multiple times now and it’s working very well. Even if you’re ontop of it or smth.

Thanks, I’ll try this tomorrow :))

do you anchor that part? :thinking: :thinking: :thinking: :thinking: :thinking:

That’s why it’s a bit weird for me.

Really I would be using something like this:

1 Like

Yep, Everything is anchored
[30characters]