Tank Chassis Behavior with Constraints

Ultimately my goal is to create an easy Plug n’ Play utility for users who wants exactly how a current Tank Chassis car handles (1 Vehicle, 4 wheels with Surface Hinges) but with the new constraints as Roblox further pushes surface hinges off the platform.

While doing this though, I’m a bit confused by the VehicleController Module is that something called MoveVector seems to be taken into account, and might cause some of the strange conditions found in the video below.

function VehicleController:Update(moveVector, cameraRelative, usingGamepad)
	if self.vehicleSeat then
		if cameraRelative then
			-- This is the default steering mode
			moveVector = moveVector + Vector3.new(self.steer, 0, self.throttle)
			if usingGamepad and onlyTriggersForThrottle and useTriggersForThrottle then
				self.vehicleSeat.ThrottleFloat = -self.throttle
			else
				self.vehicleSeat.ThrottleFloat = -moveVector.Z
			end
			self.vehicleSeat.SteerFloat = moveVector.X

			return moveVector, true
		else
			-- This is the path following mode
			local localMoveVector = self.vehicleSeat.Occupant.RootPart.CFrame:VectorToObjectSpace(moveVector)

			self.vehicleSeat.ThrottleFloat = self:ComputeThrottle(localMoveVector)
			self.vehicleSeat.SteerFloat = self:ComputeSteer(localMoveVector)

			return ZERO_VECTOR3, true
		end
	end
	return moveVector, false
end

When using Throttle and Steer at the same time, one side of the car continues spinning at the normal speeds, whereas the other side of the car will spin the tires are a slower rate, that I can’t quite figure out what exactly the math behind that rate is. As well, depending on which of the buttons you started pressing first (in the example below, Throttle or Steer Right) you get a different reaction when the second button is being pushed.

As can be seen in the video, when Throttle is press first, and then steering to the right is added, the right side wheels move forward.

When steering to the right is pressed first, and then throttle is added, the right side wheels move backward.

Here as well is the current Roblox PlayerModule. Any help deciphering what exactly is happening here would be greatly appreciated, as I’m just perplexed by what causes this behavior, and it makes it difficult to re-create when you haven’t a clue where to start. (The exert above is lines 134-158 of the VehicleController module.)
PlayerModule.rbxm (111.6 KB)

2 Likes