39 lines
977 B
GDScript
39 lines
977 B
GDScript
extends CharacterBody2D
|
|
|
|
@export var Speed = 2500
|
|
@export var FrictionMult = 5
|
|
|
|
@export var Sprite : Sprite2D
|
|
var SpriteTurningSpeed = 5
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _physics_process(delta: float) -> void:
|
|
|
|
var direction = Vector2(0,0)
|
|
|
|
if Input.is_action_pressed("up"):
|
|
direction.y -= 1
|
|
if Input.is_action_pressed("down"):
|
|
direction.y += 1
|
|
if Input.is_action_pressed("left"):
|
|
direction.x -= 1
|
|
if Input.is_action_pressed("right"):
|
|
direction.x += 1
|
|
|
|
direction = direction.normalized()
|
|
|
|
velocity += direction * Speed * delta
|
|
|
|
velocity = velocity.move_toward(Vector2(0,0), delta * clamp(velocity.length() * FrictionMult, 1000, 10000))
|
|
|
|
if velocity.length() > 0.1:
|
|
Sprite.rotation = rotate_toward(Sprite.rotation,velocity.angle(),delta*SpriteTurningSpeed)
|
|
|
|
move_and_slide()
|