Advertisement
Guest User

Drive2

a guest
Dec 12th, 2018
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. local player = game.Players.LocalPlayer.Name
  2. local car = game.Workspace[player.."Car"]
  3. local seat = car.VehicleSeat
  4. local leftDrive = car.RearAxle.LeftDrive
  5. local rightDrive = car.RearAxle.RightDrive
  6. local steerHingeR = car.AxleR.SteerHingeR
  7. local steerHingeL = car.AxleL.SteerHingeL
  8. local RunService = game:GetService("RunService")
  9. local UserInputService = game:GetService("UserInputService")
  10.  
  11. local function onRenderStep(deltaTime)
  12. local maxSpeed = seat.Configuration.MaxSpeed.Value
  13. local torque = seat.Configuration.Torque.Value * 1000
  14. leftDrive.AngularVelocity = maxSpeed * seat.Throttle
  15. rightDrive.AngularVelocity = -maxSpeed * seat.Throttle
  16. rightDrive.MotorMaxTorque = torque
  17. leftDrive.MotorMaxTorque = torque
  18. local steeringAngle = seat.Configuration.SteerAngle.Value
  19. local turnSpeed = seat.Configuration.TurnSpeed.Value
  20. steerHingeR.TargetAngle = steeringAngle * seat.Steer
  21. steerHingeL.TargetAngle = steeringAngle * seat.Steer
  22. steerHingeR.AngularSpeed = turnSpeed
  23. steerHingeL.AngularSpeed = turnSpeed
  24.  
  25. if seat.Throttle == -1 then
  26. car.TailLights1.SpotLight.Enabled = true
  27. car.TailLights2.SpotLight.Enabled = true
  28. else
  29. car.TailLights1.SpotLight.Enabled = false
  30. car.TailLights2.SpotLight.Enabled = false
  31. end
  32. end
  33. RunService.RenderStepped:Connect(onRenderStep)
  34.  
  35.  
  36. local function BrakeInputBegan(input,gameProcessed) -- Handbrake
  37. if input.UserInputType == Enum.UserInputType.Keyboard then
  38. while UserInputService:IsKeyDown(Enum.KeyCode.B) == true do
  39. wait()
  40. local lockangle = leftDrive.CurrentAngle
  41. local lockangle2 = rightDrive.CurrentAngle
  42. leftDrive.ActuatorType = "Servo"
  43. rightDrive.ActuatorType = "Servo"
  44. leftDrive.TargetAngle = lockangle
  45. leftDrive.ServoMaxTorque = 100000
  46. rightDrive.TargetAngle = lockangle2
  47. rightDrive.ServoMaxTorque = 100000
  48. end
  49. leftDrive.ActuatorType = "Motor"
  50. rightDrive.ActuatorType = "Motor"
  51. end
  52. end
  53.  
  54. UserInputService.InputBegan:connect(function(input, processed)
  55. if input.UserInputType == Enum.UserInputType.Gamepad1 then
  56. if input.KeyCode == Enum.KeyCode.ButtonB then
  57. local lockangle = leftDrive.CurrentAngle
  58. local lockangle2 = rightDrive.CurrentAngle
  59. leftDrive.ActuatorType = "Servo"
  60. rightDrive.ActuatorType = "Servo"
  61. leftDrive.TargetAngle = lockangle
  62. leftDrive.ServoMaxTorque = 100000
  63. rightDrive.TargetAngle = lockangle2
  64. rightDrive.ServoMaxTorque = 100000
  65. end
  66. end
  67. end)
  68.  
  69. UserInputService.InputEnded:connect(function(input, processed)
  70. if input.UserInputType == Enum.UserInputType.Gamepad1 then
  71. if input.KeyCode == Enum.KeyCode.ButtonB then
  72. leftDrive.ActuatorType = "Motor"
  73. rightDrive.ActuatorType = "Motor"
  74. end
  75. end
  76. end)
  77.  
  78.  
  79. UserInputService.InputBegan:connect(BrakeInputBegan)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement