- Edited
I'm doing an Asteroids clone, and I got a nice "tank control" from the official Godot tutorials, but I'm stuck trying to add acceleration/deceleration to my ship.
var speed = 250
var rotate_speed = 1.5
var rotate_dir = 0
var velocity = Vector2()
func getinput():
rotate_dir = 0
velocity = Vector2()
if Input.is_action_pressed("p1_right"):
rotate_dir += 1
if Input.is_action_pressed("p1_left"):
rotate_dir -= 1
if Input.is_action_pressed("p1_up"):
velocity = Vector2(0, -speed).rotated(rotation)
if Input.is_action_pressed("p1_down"):
velocity = Vector2(0, speed).rotated(rotation)
func _physics_process(delta: float) -> void:
getinput()
rotation += rotate_dir * rotate_speed * delta
velocity = move_and_slide(velocity)
Would appreciate some help and ideas in how to implement it.