Advertisement
Guest User

Untitled

a guest
Feb 10th, 2020
458
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends VehicleBody
  2.  
  3. var speed
  4. var steerAngle
  5. var yRotation
  6. const acceleration = 100
  7.  
  8. func steer():
  9. if Input.is_action_pressed("ui_left"): #Steer and rotate
  10. if steerAngle < 0.25:
  11. steerAngle += 0.05
  12. else:
  13. steerAngle = 0.25
  14.  
  15. if yRotation < 0.01:
  16. yRotation += 0.0025
  17. elif Input.is_action_pressed("ui_right"):
  18. if steerAngle > -0.25:
  19. steerAngle -= 0.05
  20. else:
  21. steerAngle = -0.25
  22.  
  23. if yRotation > -0.01:
  24. yRotation -= 0.0025
  25. else:
  26. steerAngle = 0
  27. yRotation = 0
  28.  
  29. set_steering(steerAngle)
  30. if speed != 0: #Rotate only when moving
  31. rotate_y(yRotation)
  32.  
  33. func accelerate():
  34. if Input.is_action_pressed("accelerate"): #Acceleration
  35. if speed < 1000:
  36. speed += acceleration
  37. else:
  38. speed = 1000
  39. else: #Inertia and stop
  40. if speed > 0:
  41. speed -= 5
  42. else:
  43. speed = 0
  44. set_engine_force(speed) #Control
  45.  
  46. # Called when the node enters the scene tree for the first time.
  47. func _ready():
  48. speed = 0
  49. yRotation = 0
  50.  
  51. # Called every frame. 'delta' is the elapsed time since the previous frame.
  52. func _process(delta):
  53. accelerate()
  54. steer()
Advertisement
RAW Paste Data Copied
Advertisement