2020-06-14 00:29:58 +02:00
|
|
|
extends KinematicBody
|
|
|
|
|
|
|
|
const GRAVITY = 9.8
|
|
|
|
|
|
|
|
var velocity = Vector3.ZERO
|
|
|
|
|
2020-06-14 00:38:15 +02:00
|
|
|
var walkDirection = Vector2.ZERO
|
|
|
|
|
2020-06-14 00:29:58 +02:00
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
|
|
|
|
2020-06-14 00:38:15 +02:00
|
|
|
func gravity():
|
|
|
|
self.velocity.y -= GRAVITY
|
|
|
|
|
|
|
|
func walk():
|
|
|
|
walkDirection = Vector2.ZERO
|
|
|
|
|
2020-06-14 00:47:26 +02:00
|
|
|
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
|
|
|
|
|
2020-06-14 00:50:54 +02:00
|
|
|
#print("Player walkDirection: ", walkDirection)
|
2020-06-14 00:29:58 +02:00
|
|
|
|
|
|
|
func motion(delta):
|
2020-06-14 00:38:15 +02:00
|
|
|
self.move_and_slide(velocity * delta, Vector3.UP)
|
2020-06-14 00:29:58 +02:00
|
|
|
#rpc("move_and_slide", velocity, Vector3.UP)
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
2020-06-14 00:38:15 +02:00
|
|
|
gravity()
|
|
|
|
walk()
|
2020-06-14 00:29:58 +02:00
|
|
|
motion(delta)
|
|
|
|
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
pass # Replace with function body.
|
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
#func _process(delta):
|
|
|
|
# pass
|