Hello. I am working on a game heavily reliant on Roblox’s physics, and I have a vehicle that will move kind of like a motorcycle, but also be able to teeter left and right as it gets impacted. I decided to use a massless part that is stuck in the plane of the floor as my “carrier” (yellow), and the rest of the vehicle+mass has a hinge constraint to the carrier with a root (green):
Because of this, there are no forces of friction, and I have to make custom correctional forces for drag and friction. I am using forces as the body movers, but the issue is whether I apply the force to the root or carrier (I tested both), I get a jitter when moving:
Is this because of the hinge constraint conflicting as it is being dragged? How would I fix this? Is there a smarter approach to this that keeps smooth gameplay but also has realistic, tuneable, and fun collisions?
Here are the relevant scripts incase they help:
local function zeroHorizontalSpeed(part)
part.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
end
local function updateHorse(player, state)
local horse = getHorse(player)
local root = getRequired(horse, HorseConfig.RootPartName, "BasePart")
local carrier = getRequired(horse, HorseConfig.CarrierPartName, "BasePart")
local driveForce = getRequired(root, "HorseDriveForce", "VectorForce")
local dragForce = getRequired(root, "HorseDragForce", "VectorForce")
local drive = HorseConfig.Drive
local localVelocity = -root.CFrame:VectorToObjectSpace(root.AssemblyLinearVelocity)
local speed = math.abs(localVelocity.Z)
local direction = 0
if localVelocity.Z > 0 then
direction = 1
elseif localVelocity.Z < 0 then
direction = -1
end
local forwardDragScalar = drive.ForwardAccelerationForce / (drive.MaxForwardSpeed * drive.MaxForwardSpeed)
local reverseDragScalar = drive.ReverseAccelerationForce / (drive.MaxReverseSpeed * drive.MaxReverseSpeed)
driveForce.Force = Vector3.zero
dragForce.Force = Vector3.zero
print(speed)
if state.ForwardInput > 0 then
driveForce.Force = Vector3.new(drive.ForwardAccelerationForce, 0, 0)
if direction == 1 and speed > 0 then
dragForce.Force = Vector3.new(-(forwardDragScalar * speed * speed), 0, 0)
end
elseif state.ForwardInput < 0 then
driveForce.Force = Vector3.new(-drive.ReverseAccelerationForce, 0, 0)
if direction == -1 and speed > 0 then
dragForce.Force = Vector3.new(reverseDragScalar * speed * speed, 0, 0)
end
else
if speed > drive.StopSnapSpeed then
warn("Slowing")
state.Stopped = false
if direction == 1 then
dragForce.Force = Vector3.new(-drive.CoastDamping, 0, 0)
elseif direction == -1 then
dragForce.Force = Vector3.new(drive.CoastDamping, 0, 0)
end
elseif not state.Stopped then
warn("Stopped")
state.Stopped = true
zeroHorizontalSpeed(carrier)
zeroHorizontalSpeed(root)
driveForce.Force = Vector3.zero
dragForce.Force = Vector3.zero
zeroHorizontalSpeed(carrier)
zeroHorizontalSpeed(root)
end
end
end
--Settings module script in RS
HorseConfig.Drive = {
ForwardAccelerationForce = 8000,
ReverseAccelerationForce = 4000,
MaxForwardSpeed = 80,
MaxReverseSpeed = 40,
CoastDamping = 3000,
StopSnapSpeed = 5,
}
Thanks!
