Velocity discrepancies when rapidly CFraming a model with a seat

I’m working on a space game where players can walk around on different planets or spaceships that are moving relative to each other, to allow physic objects to work, I bind a function to RunService.Stepped to CFrame unanchored models into the right spots for the physics simulation. This works well for most models, except anything containing a seat, which causes the seat and all parts connected to it through welds to change their velocity slightly, this causes the part to wobble slightly, and starts the fling itself when the player sits in the seat.

Here are some screenshots of me probing the magnitude of the difference between the intended and actual values of the position and velocity properties of two unanchored models, “platform” a platform being flung through the sky, without a seat, and “vehicle”, a platform with a seat stationary on the ground. The first image is a control group where I removed vehicle’s seat.

NoSeat
(no seat on vehicle)

Seat
(seat on vehicle)

I’ve tried briefly disabling the the welds while CFraming to see if that would help, but I couldn’t seem to re-enable the weld before the physics step. I also tried manually setting the velocity of the primary part to the intended value, but it didn’t seem to fix it somehow.

1 Like

Could you post the code you use to reposition these models?

This is the code, it’s in a for loop that moves planets. GetPosition(v), GetVelocity(v) and SetCFrame(v) are simple functions that allow me to work with Parts and Models in the same function. It’s pretty much just " “v.CFrame =” or “v:SetPrimaryPartCFrame()” and so on.

			local Descendents = MasterGravityManager.GetDescendants(Gravity.Satellite)
			
			--Find relative position of each physics object
			local DescendentsLocalPos = {}
			for index,value in pairs(Descendents) do
				DescendentsLocalPos[value] = GetPosition(value) - GetPosition(Gravity.Satellite)
			end
			
			--Current position of planet, new position, and change in position
			local OrbitPos = GetPosition(Gravity.Satellite)
			local NewOrbitPos = Gravity:OrbitalPosition(step) + GetPosition(Gravity.Parent)
			local dp = NewOrbitPos - OrbitPos
			
			--Move the planet
			SetCFrame(Gravity.Satellite,CFrame.new(NewOrbitPos)*CFrame.Angles(GetOrientation(Gravity.Satellite)))
			
			--Physics object position correction to make sure everything is in the correct spot
			for index,value in pairs(Descendents) do
				if(MasterGravityManager.GetData(value).Type == "PartGravity") then
					
					local oldVel = GetVelocity(value)
					
					SetCFrame(value,CFrame.new(NewOrbitPos+DescendentsLocalPos[value])*CFrame.Angles(GetOrientation(value)))
					
					print((GetVelocity(value)-oldVel).Magnitude, value, "Velocity Error")
					
					print((GetPosition(value) - (DescendentsLocalPos[value] + NewOrbitPos)).Magnitude, value, "Position Error")
					
				end
			end

Maybe SetPrimaryPartCFrame interacts weirdly with seats. I wouldn’t recommend it anyways, since it has some issues with precision over time.

Does it occur if you just set the primary part’s CFrame directly and let the WeldConstraints solve the rest of it for you (and are they WeldConstraints or Welds, because that might matter too)?

Could you maybe record a short video of the problem occurring? It’s somewhat hard to tell.

I’m away from my computer right now, so I can’t test updating the cframe on the primary part directly, but I can confirm that both welds and weld constraints cause this problem, as for the video, I have a recording of it on another topic I made on this problem before I narrowed it down to seats and velocity problems https://devforum.roblox.com/t/trouble-with-seated-player-physics-with-rapid-cframe-changing-and-egomooses-wallstick-controller/1044116