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:
FlipBodyPosition:
FlipBodyGyro:
Solutions I’ve Tried So Far:
- 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.
- 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.
- Disabling the vehicle scripts to make sure that no script is affecting the physics of the car. BodyPosition still doesn’t work.
- Parenting the forces to the Chassis before changing their properties, and vice versa.
- Everything that’s listed in the Troubleshooting section of the BodyPosition reference in Roblox Wiki.
Couple things to note:
- When adding BodyMovers, the network owner is always the server.
- 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.
- The other BodyGyro and BodyPosition have a MaxForce and MaxTorque of Vector3.new(), so they don’t affect anything.
- The assembly is not anchored.
- 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 ), and then if I manually flip it up again, it destroys the forces it adds, proving that the code above works.