From 7057aafcb1b1b600bfa6827ab189850456697512 Mon Sep 17 00:00:00 2001 From: unfa Date: Sun, 14 Jun 2020 01:32:44 +0200 Subject: [PATCH] Walking direction checks in _input working. --- Game.tscn | 1 + Player.gd | 39 ++++++++++++++++++++++++++++----------- Player.tscn | 9 ++++----- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Game.tscn b/Game.tscn index d7cef28..3649fd1 100644 --- a/Game.tscn +++ b/Game.tscn @@ -10,3 +10,4 @@ script = ExtResource( 2 ) [node name="Level" parent="." instance=ExtResource( 3 )] [node name="Player" parent="." instance=ExtResource( 1 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 12.7215, 13.0596, -0.85251 ) diff --git a/Player.gd b/Player.gd index 2afa638..614424c 100644 --- a/Player.gd +++ b/Player.gd @@ -2,6 +2,7 @@ extends KinematicBody const GRAVITY = 9.8 const JUMP_VELOCITY = 400 +const WALK_VELOCITY = 150 var velocity = Vector3.ZERO @@ -15,18 +16,10 @@ func gravity(): self.velocity.y -= GRAVITY func walk(): - walkDirection = Vector2.ZERO + walkDirection = walkDirection.normalized() + print("Player walkDirection: ", walkDirection) - if Input.is_action_pressed("MoveForward"): - walkDirection.x += 1 - if Input.is_action_pressed("MoveBack"): - walkDirection.x -= 1 - if Input.is_action_pressed("MoveRight"): - walkDirection.y += 1 - if Input.is_action_pressed("MoveLeft"): - walkDirection.y -= 1 - - #print("Player walkDirection: ", walkDirection) + #velocity.xz = WALK_VELOCITY * walkDirection remote func jump(): print("JUMP") @@ -38,13 +31,37 @@ func motion(delta): func _physics_process(delta): gravity() + + rpc("walk") walk() + motion(delta) func _input(event): + #print(event) + if event.is_action_pressed("MoveJump"): rpc("jump") jump() + + if event.is_action_pressed("MoveForward"): + walkDirection.x += 1 + if event.is_action_pressed("MoveBack"): + walkDirection.x -= 1 + if event.is_action_pressed("MoveRight"): + walkDirection.y += 1 + if event.is_action_pressed("MoveLeft"): + walkDirection.y -= 1 + + if event.is_action_released("MoveForward"): + walkDirection.x += -1 + if event.is_action_released("MoveBack"): + walkDirection.x -= -1 + if event.is_action_released("MoveRight"): + walkDirection.y += -1 + if event.is_action_released("MoveLeft"): + walkDirection.y -= -1 + # Called when the node enters the scene tree for the first time. func _ready(): diff --git a/Player.tscn b/Player.tscn index a89dc6f..8a595d7 100644 --- a/Player.tscn +++ b/Player.tscn @@ -2,12 +2,11 @@ [ext_resource path="res://Player.gd" type="Script" id=1] -[sub_resource type="CapsuleShape" id=3] +[sub_resource type="CapsuleShape" id=1] -[sub_resource type="CapsuleMesh" id=4] +[sub_resource type="CapsuleMesh" id=2] [node name="Player" type="KinematicBody"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 12.2035, 0 ) script = ExtResource( 1 ) [node name="Camera" type="Camera" parent="."] @@ -15,9 +14,9 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.70316, -0.0651628 ) [node name="CollisionShape" type="CollisionShape" parent="."] transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 0, 0 ) -shape = SubResource( 3 ) +shape = SubResource( 1 ) [node name="MeshInstance" type="MeshInstance" parent="."] transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 0, 0 ) -mesh = SubResource( 4 ) +mesh = SubResource( 2 ) material/0 = null