i use the roblox car kit for my cars. it works totally fine but the only problem is it can’t drive up hills.
I’ve messed around with friction on the road and wheels, but it still does not go full speed when its going up a hill
Can we see the script that moves the car?
this is the script i got from the kit. I changed 2 lines but those should not cause this issue
local vehicleSeat = script.Parent.Base.VehicleSeat
local motorFR = script.Parent.WheelFR:FindFirstChildWhichIsA("CylindricalConstraint", true)
local motorFL = script.Parent.WheelFL:FindFirstChildWhichIsA("CylindricalConstraint", true)
local motorBR = script.Parent.WheelBR:FindFirstChildWhichIsA("CylindricalConstraint", true)
local motorBL = script.Parent.WheelBL:FindFirstChildWhichIsA("CylindricalConstraint", true)
local springFR = script.Parent.WheelFR:FindFirstChildWhichIsA("SpringConstraint", true)
local springFL = script.Parent.WheelFL:FindFirstChildWhichIsA("SpringConstraint", true)
local springBR = script.Parent.WheelBR:FindFirstChildWhichIsA("SpringConstraint", true)
local springBL = script.Parent.WheelBL:FindFirstChildWhichIsA("SpringConstraint", true)
local wheelHingeR = script.Parent.WheelFR:FindFirstChildWhichIsA("HingeConstraint", true)
local wheelHingeL = script.Parent.WheelFL:FindFirstChildWhichIsA("HingeConstraint", true)
-- TUNING VALUES
----------------------------------------
-- Factor of torque applied to get the wheels spinning
-- Larger number generally means faster acceleration
local TORQUE = 5800
-- Factor of torque applied to change the wheel direction
-- Larger number generally means faster braking
local BRAKING_TORQUE = math.huge
-- Max angle the wheels will reach when turning
-- Higher number means sharper turning, but too high means the wheels might hit the car base
local MAX_TURN_ANGLE = 20
-- Car max speed
local MAX_SPEED = 35
----------------------------------------
-- HELPER FUNCTIONS
----------------------------------------
-- Set the "MotorMaxTorque" property on all of the CylindricalConstraint motors
local function setMotorTorque(torque)
motorFR.MotorMaxTorque = torque
motorFL.MotorMaxTorque = torque
motorBR.MotorMaxTorque = torque
motorBL.MotorMaxTorque = torque
end
-- Set the "AngularVelocity" property on all of the CylindricalConstraint motors
local function setMotorVelocity(vel)
motorFL.AngularVelocity = vel
motorBL.AngularVelocity = vel
-- Motors on the right side are facing the opposite direction, so negative velocity must be used
motorFR.AngularVelocity = -vel
motorBR.AngularVelocity = -vel
end
-- Calculate the average linear velocity of the car based on the rate at which all wheels are spinning
local function getAverageVelocity()
local vFR = -motorFR.Attachment1.WorldAxis:Dot(motorFR.Attachment1.Parent.RotVelocity)
local vRR = -motorBR.Attachment1.WorldAxis:Dot(motorBR.Attachment1.Parent.RotVelocity)
local vFL = motorFL.Attachment1.WorldAxis:Dot(motorFL.Attachment1.Parent.RotVelocity)
local vRL = motorBL.Attachment1.WorldAxis:Dot(motorBL.Attachment1.Parent.RotVelocity)
return 0.25 * ( vFR + vFL + vRR + vRL )
end
-- DRIVE LOOP
----------------------------------------
while true do
-- Input values taken from the VehicleSeat
local steerFloat = vehicleSeat.SteerFloat -- Forward and backward direction, between -1 and 1
local throttle = vehicleSeat.ThrottleFloat -- Left and right direction, between -1 and 1
-- Convert "steerFloat" to an angle for the HingeConstraint servos
local turnAngle = steerFloat * MAX_TURN_ANGLE
wheelHingeR.TargetAngle = turnAngle
wheelHingeL.TargetAngle = turnAngle
-- Apply torque to the CylindricalConstraint motors depending on our throttle input and the current speed of the car
local currentVel = getAverageVelocity()
local targetVel = 0
local motorTorque = 0
local MAX_SPEED = script.Parent.Configuration.MaxSpeed.Value
-- Idling
if math.abs(throttle) < 0.1 then
motorTorque = 100
-- Accelerating
elseif math.abs(throttle * currentVel) > 0 then
-- Reduce torque with speed (if torque was constant, there would be a jerk reaching the target velocity)
-- This also produces a reduction in speed when turning
local r = math.abs(currentVel) / MAX_SPEED
-- Torque should be more sensitive to input at low throttle than high, so square the "throttle" value
motorTorque = math.exp( - 3 * r * r ) * TORQUE * throttle * throttle
targetVel = math.sign(throttle) * 10000 -- Arbitrary large number
-- Braking
else
motorTorque = BRAKING_TORQUE * throttle * throttle
end
-- Use helper functions to apply torque and target velocity to all motors
setMotorTorque(motorTorque)
setMotorVelocity(targetVel)
wait()
end
You can increase the speed when it touches the hill so that it has enough power to go up the hill
You could always increase the torque.
2 Likes
Sorry for the bump.
I don’t know if you fixed this but it’s pretty easy, make a for loop through every wheel and increase their friction using Custom Physical Properties
for _, wheel in pairs(car.Wheels:GetChildren()) do
--[[ This will make the wheels have the triple friction that a normal part should have,
and your car may be able to climb hills ]]
local CustomPhysics = PhysicalProperties.new(1, 3, 1, 1, 1)
wheel.CustomPhysicalProperties = CustomPhysics
end
1 Like