diagonal movement
This commit is contained in:
parent
7a6a355e61
commit
5f0208ab7a
3 changed files with 8 additions and 7 deletions
|
@ -15,15 +15,17 @@ func _ready():
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta):
|
func _physics_process(delta):
|
||||||
var direction = Vector2.ZERO
|
var direction = Vector2.ZERO
|
||||||
if Input.is_action_pressed("right"):
|
if Input.is_action_pressed("right"):
|
||||||
direction.x += 1
|
direction.x += 1
|
||||||
if Input.is_action_pressed("left"):
|
if Input.is_action_pressed("left"):
|
||||||
direction.x -= 1
|
direction.x -= 1
|
||||||
if Input.is_action_pressed("up"):
|
if Input.is_action_pressed("up"):
|
||||||
direction.y += 1
|
|
||||||
if Input.is_action_pressed("down"):
|
|
||||||
direction.y -= 1
|
direction.y -= 1
|
||||||
print(direction)
|
if Input.is_action_pressed("down"):
|
||||||
|
direction.y += 1
|
||||||
|
print(direction.normalized()*speed)
|
||||||
|
direction = direction.normalized() * speed
|
||||||
|
move_and_collide(direction)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Texture/grass.png" type="Texture" id=1]
|
[ext_resource path="res://Texture/grass.png" type="Texture" id=1]
|
||||||
[ext_resource path="res://sprites/player.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://sprites/player.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://Scripts/player.gd" type="Script" id=3]
|
|
||||||
|
|
||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Node2D"]
|
||||||
|
|
||||||
|
@ -15,4 +14,3 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="AnimatedSprite" parent="." instance=ExtResource( 2 )]
|
[node name="AnimatedSprite" parent="." instance=ExtResource( 2 )]
|
||||||
script = ExtResource( 3 )
|
|
||||||
|
|
|
@ -225,6 +225,7 @@ animations = [ {
|
||||||
|
|
||||||
[node name="KinematicBody2D" type="KinematicBody2D"]
|
[node name="KinematicBody2D" type="KinematicBody2D"]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
speed = 2
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
shape = SubResource( 44 )
|
shape = SubResource( 44 )
|
||||||
|
|
Loading…
Reference in a new issue