Switch to KinematicBody2D so we can think of walls etc

main
Olivier 'reivilibre' 2023-01-06 22:15:47 +00:00
parent 66ca708f52
commit bf9bf97da0
2 changed files with 4 additions and 7 deletions

View File

@ -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)

View File

@ -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="."]