diff --git a/characters/player/Player.gd b/characters/player/Player.gd index 2be9fa1..b4f06e4 100644 --- a/characters/player/Player.gd +++ b/characters/player/Player.gd @@ -1,4 +1,4 @@ -extends Area2D +extends KinematicBody2D export var speed = 200 # How fast the player will move (pixels/sec). @@ -8,8 +8,7 @@ var screen_size # Size of the game window. func _ready(): screen_size = get_viewport_rect().size -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): +func _physics_process(delta): var velocity = Vector2.ZERO # The player's movement vector. velocity.x += Input.get_action_strength("move_right") - Input.get_action_strength("move_left") velocity.y += Input.get_action_strength("move_down") - Input.get_action_strength("move_up") @@ -20,6 +19,4 @@ func _process(delta): else: $AnimatedSprite.stop() - position += velocity * delta - position.x = clamp(position.x, 0, screen_size.x) - position.y = clamp(position.y, 0, screen_size.y) + self.move_and_slide(velocity) diff --git a/characters/player/Player.tscn b/characters/player/Player.tscn index 6ccd631..21c14f5 100644 --- a/characters/player/Player.tscn +++ b/characters/player/Player.tscn @@ -14,7 +14,7 @@ animations = [ { [sub_resource type="CircleShape2D" id=2] radius = 23.0217 -[node name="Player" type="Area2D"] +[node name="Player" type="KinematicBody2D"] script = ExtResource( 2 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."]