Switch to KinematicBody2D so we can think of walls etc
This commit is contained in:
parent
66ca708f52
commit
bf9bf97da0
|
@ -1,4 +1,4 @@
|
||||||
extends Area2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
|
|
||||||
export var speed = 200 # How fast the player will move (pixels/sec).
|
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():
|
func _ready():
|
||||||
screen_size = get_viewport_rect().size
|
screen_size = get_viewport_rect().size
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
func _physics_process(delta):
|
||||||
func _process(delta):
|
|
||||||
var velocity = Vector2.ZERO # The player's movement vector.
|
var velocity = Vector2.ZERO # The player's movement vector.
|
||||||
velocity.x += Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
|
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")
|
velocity.y += Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
|
||||||
|
@ -20,6 +19,4 @@ func _process(delta):
|
||||||
else:
|
else:
|
||||||
$AnimatedSprite.stop()
|
$AnimatedSprite.stop()
|
||||||
|
|
||||||
position += velocity * delta
|
self.move_and_slide(velocity)
|
||||||
position.x = clamp(position.x, 0, screen_size.x)
|
|
||||||
position.y = clamp(position.y, 0, screen_size.y)
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ animations = [ {
|
||||||
[sub_resource type="CircleShape2D" id=2]
|
[sub_resource type="CircleShape2D" id=2]
|
||||||
radius = 23.0217
|
radius = 23.0217
|
||||||
|
|
||||||
[node name="Player" type="Area2D"]
|
[node name="Player" type="KinematicBody2D"]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
|
|
Loading…
Reference in New Issue