Physics Problem I've Been Working On For the Past 12 Hours: Immovable Assembly

I’m scripting vehicle flipping for my game. The vehicle is the one found in the default Jeep Racing game, but is modified to an insignificant extent: the only noticeable thing that’s changed is the mesh. The assembly setup and scripts are the same. The client verifies that the vehicle is upside down by checking rotation, sends the request to the server, and the server checks the same thing before attempting to flip the vehicle.

The problem is that when the server tries to flip the vehicle, the body movers don’t affect it at all. The server creates a BodyPosition to move the vehicle 10 studs above the ground. I’ve checked this calculated position, and it’s always reliable. It then adds a BodyGyro to rotate it to the correct orientation. However, I’ve tried SO many things, but the car just doesn’t move at all. Here are some screenshots below of the objects and properties after the server attempts to flip them.

Vehicle:
image

FlipBodyPosition:
image

FlipBodyGyro:
image

Solutions I’ve Tried So Far:

  1. Removing all other forces in the vehicle that aren’t used for flipping, including forces that don’t apply any force/torque. Still doesn’t move.
  2. Manually putting the BodyPosition into the Chassis during gameplay. Still doesn’t move. However, a WEIRD thing I’ve discovered is that if I parent the BodyPosition to another part in the assembly besides the Chassis, the BodyPosition works.
  3. Disabling the vehicle scripts to make sure that no script is affecting the physics of the car. BodyPosition still doesn’t work.
  4. Parenting the forces to the Chassis before changing their properties, and vice versa.
  5. Everything that’s listed in the Troubleshooting section of the BodyPosition reference in Roblox Wiki.

Couple things to note:

  1. When adding BodyMovers, the network owner is always the server.
  2. The “CustomCode” module is empty. The scripts that run the vehicle are in a different place but they are the same as the ones in the Jeep Racing.
  3. The other BodyGyro and BodyPosition have a MaxForce and MaxTorque of Vector3.new(), so they don’t affect anything.
  4. The assembly is not anchored.
  5. Additionally, the assembly isn’t overshooting, since it’s not even moving at all. I’ve tried a bunch of combinations of MaxForce, P, and D.

Here is the server sided code that adds the BodyMovers to flip the car:

			if Chass:FindFirstChild('FlipBodyGyro') then
				VehicleExists.FlipBodyGyro:Destroy()
			end
			
			if Chass:FindFirstChild('FlipBodyPosition') then
				VehicleExists.FlipBodyPosition:Destroy()
			end
			
			local VehicleMass = VehicleModule.GetVehicleMass(VehicleExists)
			
			local _, FlipPosition = VehicleModule.RaycastDown(VehicleExists)
			
			Chass:SetNetworkOwner(nil)
			
			local BodyPosition = Instance.new('BodyPosition')
			BodyPosition.Name = 'FlipBodyPosition'
			BodyPosition.Parent = Chass
			BodyPosition.Position = FlipPosition + Vector3.new(0, 10, 0) --perfect
			--BodyPosition.MaxForce = Vector3.new(workspace.Gravity * VehicleMass * 25, workspace.Gravity * VehicleMass * 25, workspace.Gravity * VehicleMass * 25)
			BodyPosition.MaxForce = Vector3.new(1 * 10^100, 1 * 10^100, 1 * 10^100)
			BodyPosition.D = 0
			BodyPosition.P = 1 * 10^100
			print(Chass:GetNetworkOwner())
			
			local BodyGyro = Instance.new('BodyGyro')
			BodyGyro.Name = 'FlipBodyGyro'
			BodyGyro.Parent = Chass
			BodyGyro.CFrame = CFrame.new()
			BodyGyro.MaxTorque = Vector3.new(VehicleMass/2, VehicleMass/2, VehicleMass/2) --MR^2 * angular acceleration
			
			--wait until correct rotation
			--destroy forces
			local pitch, roll
			repeat
				wait()
				pitch, roll = getChassisRotation(Chass)
			until -5 < pitch and pitch < 5 and -5 < roll and roll <= 5
			
			BodyGyro:Destroy()
			BodyPosition:Destroy()

Any code in the scope outside of the code above is irrelevant, the code above works as it’s told. When I flip the car upside down, it adds the forces (which don’t work :frowning:), and then if I manually flip it up again, it destroys the forces it adds, proving that the code above works.

2 Likes

I’ve decided to use lerping as an alternative since there has been no replies to this post. If someone does take the effort to reply and figure out what might’ve went wrong, I thank you in advance.

Lerping works great, btw. The only downside to it is the smoothness of the transition caused by latency.

1 Like