Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends VehicleBody
- var speed
- var steerAngle
- var yRotation
- const acceleration = 100
- func steer():
- if Input.is_action_pressed("ui_left"): #Steer and rotate
- if steerAngle < 0.25:
- steerAngle += 0.05
- else:
- steerAngle = 0.25
- if yRotation < 0.01:
- yRotation += 0.0025
- elif Input.is_action_pressed("ui_right"):
- if steerAngle > -0.25:
- steerAngle -= 0.05
- else:
- steerAngle = -0.25
- if yRotation > -0.01:
- yRotation -= 0.0025
- else:
- steerAngle = 0
- yRotation = 0
- set_steering(steerAngle)
- if speed != 0: #Rotate only when moving
- rotate_y(yRotation)
- func accelerate():
- if Input.is_action_pressed("accelerate"): #Acceleration
- if speed < 1000:
- speed += acceleration
- else:
- speed = 1000
- else: #Inertia and stop
- if speed > 0:
- speed -= 5
- else:
- speed = 0
- set_engine_force(speed) #Control
- # Called when the node enters the scene tree for the first time.
- func _ready():
- speed = 0
- yRotation = 0
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- func _process(delta):
- accelerate()
- steer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement