Walking direction checks in _input working.
parent
e3470b9437
commit
7057aafcb1
|
@ -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 )
|
||||
|
|
39
Player.gd
39
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():
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue