GMTKJam2021/Playa.gd

35 lines
1.0 KiB
GDScript3
Raw Normal View History

2021-06-12 00:17:29 +02:00
extends KinematicBody2D
2021-06-12 13:37:56 +02:00
export var ACCELERATION = 60
export var MAX_SPEED = 150
export var FRICTION = 50
2021-06-12 00:17:29 +02:00
2021-06-12 02:04:22 +02:00
var velocity = Vector2.ZERO
2021-06-12 00:17:29 +02:00
func _ready():
pass # Replace with function body.
2021-06-12 02:04:22 +02:00
func _physics_process(delta):
var direction = Vector2.UP.rotated(rotation).normalized() #Playerrotation nehmen ist sicherer
2021-06-12 13:37:56 +02:00
var forward_backward = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
2021-06-12 02:04:22 +02:00
2021-06-12 13:37:56 +02:00
if forward_backward != 0:
velocity = velocity.move_toward(direction * MAX_SPEED * forward_backward, ACCELERATION * delta)
2021-06-12 02:04:22 +02:00
else:
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
var steer_dir = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
2021-06-12 13:37:56 +02:00
if steer_dir != 0 && velocity.length() > 0:
var direction_new = direction.rotated(PI/1.5 * steer_dir * delta)
print(velocity.length())
#print(velocity.angle_to(velocity.rotated(direction_new.angle())))
velocity = velocity.rotated(direction.angle_to(direction_new))
rotate(direction.angle_to(direction_new))
2021-06-12 02:04:22 +02:00
2021-06-12 13:37:56 +02:00
velocity = move_and_slide(velocity)